Reputation: 13
Using awk I need find characters between first "." and first space " " (if exists) and replace it with space " ". I have file (test.txt) with this structure:
asdf.test.com 04-05-2014
qwer.test1.test.com 04-05-2014
asdfgg 04-05-2014
sadf
asdff.com 04-05-2014
I need this output:
asdf 04-05-2014
qwer 04-05-2014
asdfgg 04-05-2014
sadf
asdff 04-05-2014
Upvotes: 1
Views: 79
Reputation: 41460
This should do:
awk '{sub(/\..*/,x,$1)}8' test.txt
asdf04-05-2014
qwer04-05-2014
asdfgg 04-05-2014
sadf
asdff04-05-2014
Updated as suggested by BMW, since there are blank at end of line.
or this:
awk -F"[. ]" '{print $1,(NF>1?$NF:x)}' test.txt
asdf 04-05-2014
qwer 04-05-2014
asdfgg 04-05-2014
sadf
asdff 04-05-2014
Upvotes: -1
Reputation: 45333
Using sed, which can fix the issue that space in end of line.
sed 's/\.[^. ]*//g' file
Upvotes: 2
Reputation: 1
awk NF=NF FS='\\..+ ' test.txt
Result
asdf 04-05-2014 qwer 04-05-2014 asdfgg 04-05-2014 sadf asdff 04-05-2014
Upvotes: 1