Operating System - HP-UX
1830938 Members
1804 Online
110017 Solutions
New Discussion

'sed' is not working, Please correct me

 
vivek_5
Occasional Contributor

'sed' is not working, Please correct me

Hi to all,

Please do help me. i tried my best but didn't help me. looking forward for help. i have a file name "vv4" and if i run following
commands:

# cat vv4
SCAR on Fox. #
NASCAR Y 48
afsdfsdfsd
sfs
vivek
shrivastava

# cat -vet vv4
SCAR on Fox. #$
^I ^I^I^INASCAR^I^IY^I48$
afsdfsdfsd$
sfs$
vivek$
shrivastava$

you will see that first line is being end with #. what i want just find any line in the file which end with # and append the next line to it.

i tried following command but it is working.

# sed '
> /#$/ {
> N
> s/#n//
> }' vv5

now if run following command to see the out put file

# cat vv5
SCAR on Fox. #
NASCAR Y 48
afsdfsdfsd
sfs
vivek
shrivastava

# cat -vet vv5
SCAR on Fox. #$
^I ^I^I^INASCAR^I^IY^I48$
afsdfsdfsd$
sfs$
vivek$
shrivastava$

evrything is as it is as it was. it didn't merge 2nd line to first becasue first line end with #. please do help me.

waiting for help.

thanks
3 REPLIES 3
curt larson_1
Honored Contributor

Re: 'sed' is not working, Please correct me

how about trying something using awk

awk '{
if ( $0 ~ "#$" ) {
printf("%s",$0);
getline;
print $0;
}
else print $0;
}'
curt larson_1
Honored Contributor

Re: 'sed' is not working, Please correct me

compare these

sed '
/#$/ {
n
}'

and

sed '
/#$/ {
n
p
}'
Vivek_3
Advisor

Re: 'sed' is not working, Please correct me

Thanks curt!

U have solved my problem.

thanks!!