- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Urgent: Help with sed command
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2002 04:32 PM
11-07-2002 04:32 PM
Urgent: Help with sed command
i have a file with following format.
field1 field2 field3 field4
field1 field2 field3 field4
field1 field2 field3 field4
field1 field2 field3 field4
field1 field2 field3 field4
All the fields are text field. Sometime some of the fields of a line contains "\r \n". this is where problem start.
if any filed contains "\r \n", cause that line to be devided into two lines.
for example field2 of first line contains
"\r \n" then it looks like that
we have five lines instead of 4 lines.
field1 field2
field3 field4
field1 field2 field3 field4
field1 field2 field3 field4
field1 field2 field3 field4
field1 field2 field3 field4
please help me. i need help to remove "\r \n" from a line. i tried following
comand but it didn't remove "\n".
sed 's/^V^M//g' filename > newfilename
please help me.
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2002 04:46 PM
11-07-2002 04:46 PM
Re: Urgent: Help with sed command
You can try to remove these characters thru vi editor.
Open the file in vi (vi
regds
sudhakar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2002 04:47 PM
11-07-2002 04:47 PM
Re: Urgent: Help with sed command
You can try to remove these characters thru vi editor.
Open the file in vi (vi
regds
sudhakar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2002 05:06 PM
11-07-2002 05:06 PM
Re: Urgent: Help with sed command
sorry for any confusion. actually in the file the is no occurrence of "\r \n" itself. actually what I meant was, there is a carriage return and a line feed character in some of the fields.
if I run following commands
#1
> cat filename
field1 adgak field3
#2
> cat -vet filename
field1 adgak^m$ field3
Because of this it looks like that there are two lines as following.
field1 adgak
field3
if I run following commands it does not solve the problem.
Sed ???s/^M$//g??? filename >newfilename
Or
Sed ???s/^M//g??? filename >newfilename
Any help would be appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2002 05:15 PM
11-07-2002 05:15 PM
Re: Urgent: Help with sed command
botom line , is there any way to merge tow line using unix script?
please help me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2002 07:12 PM
11-07-2002 07:12 PM
Re: Urgent: Help with sed command
tr -d "\015"
That should get rid of the ^M characters.
Darrell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2002 07:21 PM
11-07-2002 07:21 PM
Re: Urgent: Help with sed command
# look for "^M" at end of line
/^M$/{
#if found, read the next line
N
# merge line
s/^Mn//
}' filename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2002 07:26 PM
11-07-2002 07:26 PM
Re: Urgent: Help with sed command
awk '{if (NF == 4 ) print $0;
else {
printf("%s",$0);
getline
print $0;
}
}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2002 10:55 PM
11-07-2002 10:55 PM
Re: Urgent: Help with sed command
- to replace a ^M yor are right to use ^V^M (typing Cntr-V Cntr-M)
- to replace \n you can use standard unix-command cat
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2002 01:09 AM
11-08-2002 01:09 AM
Re: Urgent: Help with sed command
oudartj:/home/oudartj/k1 $ more aa
asasdsdsa
sdsfdsfdsfds
oudartj:/home/oudartj/k1 $ od -xc aa
0000000 6173 6173 6473 6473 610d 0a73 6473 6664
a s a s d s d s a \r \n s d s f d
0000020 7366 6473 6664 730d 0a0a
s f d s f d s \r \n \n
0000032
oudartj:/home/oudartj/k1 $ cat aa | tr -d "\r" | od -xc
0000000 6173 6173 6473 6473 610a 7364 7366 6473
a s a s d s d s a \n s d s f d s
0000020 6664 7366 6473 0a0a
f d s f d s \n \n
0000030
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2002 10:01 AM
11-08-2002 10:01 AM
Re: Urgent: Help with sed command
Nothing helped me.
in my case i have to remove any occurance of "^M$" or "\r\n" from the middle of a line, not from the end of a line.
for example:
> cat -vet file
abcd efgh^M$
ijklmn ghkj 48
i have to remove "^M$" from the middle of line and output should be
abcd efgh ijklmn ghkj 48
so basically we have to merge next line with current line at each occurance of "^M$".
i don't have to delete line feed from the end of file.
please help me.
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2002 10:30 AM
11-08-2002 10:30 AM
Re: Urgent: Help with sed command
ascii
to change the transfer mode to text. This will fix the ^M and the end of each line
as for the /r or \n :
sed 's/\\r//g' file > file2
sed 's/\\n//g' file2 > file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2002 10:33 AM
11-08-2002 10:33 AM
Re: Urgent: Help with sed command
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2002 10:34 AM
11-08-2002 10:34 AM
Re: Urgent: Help with sed command
Try:
# dos2ux myfile|awk '{if (NR%2==0) print X$0;X=$0};END{if (NR%2==1) print X}'
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2002 10:37 AM
11-08-2002 10:37 AM
Re: Urgent: Help with sed command
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2002 10:57 AM
11-08-2002 10:57 AM
Re: Urgent: Help with sed command
It seems that your solution may work but it still need some change.
let me explain again:
i have file name "vv2". if run following commands
#1
> cat -vet vv2
NASSCAR on Fox. ^M$
^I ^I^I^INASCAR^I^IY^I48$
afsdfsdfsd$
sfs$
explination: it looks like that there are four lines. in fact there are only three line originaly. at the time of data entry user did cut & paste. because of it there is a carriage ruturn after " Fox. " because of this first line is broken into two lines.
what i want is , just remove any occurance "^M$" from the middle of the line so that it will look line as follows.
> cat -vet vv2
NASSCAR on Fox. NASCAR^I^IY^I48$
afsdfsdfsd$
sfs$
so as per your suggestion i ran following command
> dos2ux vv2 |awk '{if (NR%2==0) print X$0;X=$0};END{if (NR%2==1) print X}' > vv3
> cat -vet vv3
NASSCAR on Fox. ^I ^I^I^INASCAR^I^IY^I48$
afsdfsdfsdsfs$
the only problem i see is that last two lines are also merged.
please help me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2002 11:52 AM
11-08-2002 11:52 AM
Re: Urgent: Help with sed command
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2002 03:21 PM
11-08-2002 03:21 PM
Re: Urgent: Help with sed command
Still trying to solve my problem.
at following link i find a solution but it is not working.
http://www.student.northpark.edu/pemente/sed/sed1line.txt
# if a line ends with a backslash, append the next line to it
sed -e :a -e '/\\$/N; s/\\\n//; ta'
in my case is a line end with ^M$ then remove the ^M$ and append the next line to it. so i tried following and its not working.
sed -e :a -e '/\\^M$; s/\\\n//; ta' filename
actually i know i didn't do anything to remove "^M$" in the above command. it is giving me following error message.
$; s/\\\n//; is not a recognized function.
Please help me!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2002 10:52 PM
11-08-2002 10:52 PM
Re: Urgent: Help with sed command
"%s/^V^M//g" the control key is held down while pressing "V" then "M" and then let go of the control key
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2002 09:23 AM
11-11-2002 09:23 AM