Hi,
I have a text as below
test1 test2 test3\
test4 test5 test6 test7
newtest1 newtest2\
newtest3 newtest4 newtest5
And need this to be replaces to
test1 test2 test3 test4 test5 test6 test7
newtest1 newtest2 newtest3 newtest4 newtest5
So my requirement is to remove the EOL if the last character is \.
I tried my luck and searches but but unsuccessfull.. help here is very much appreciated.
Thanks
Praveen
Not sure what OS you're using or if the file contents will be static like the example you gave but this may work:
awk '{sub(/\\/, "")}!(NR%2){print $0" "p}{p=$0}' file.txt
Output:
test4 test5 test6 test7 test1 test2 test3
newtest3 newtest4 newtest5 newtest1 newtest2
Hope this helps point you in the right direction.
sulti
3
Try something like this:
sed "/\\\\$/ { N; s/\\\\\n/ /}" filename
Sorry , awk is not working as expected ....
#cat test_sudo
User_Alias TEST=test1,test2,test3,test4,test5,\
test6,test7,ltest8,test9
#awk '{sub(/\\/, "")}!(NR%2){print $0" "p}{p=$0}' test_sudo
test6,test7,ltest8,test9 User_Alias TEST=test1,test2,test3,test4,test5,
#sed "/\\\\$/ { N; s/\\\\\n/ /}" test_sudo
sed: 0602-404 Function /\\$/ { N; s/\\\n/ /} cannot be parsed.
This is an AIX machine
hergp
5
Let a simple shell script do the job:
]$ cat test_sudo
User_Alias TEST=test1,test2,test3,test4,test5,\
test6,test7,ltest8,test9
$ while read line
> do
> echo "$line"
> done
User_Alias TEST=test1,test2,test3,test4,test5, test6,test7,ltest8,test9
The read
shell-builtin has the capability to deal with \-NL by itself.
Another approach:
awk '/\\$/{printf substr($0,1,length-1) FS; next}1' file
Use nawk or /usr/xpg4/bin/awk on Solaris.