jbt828
October 10, 2009, 7:08pm
1
I'm new to Unix scripting and I'm not sure if this can be done. Example:
search (grep) in a file for 'Control ID' and then replace with 4 blanks 7 bytes before 'Control ID.
input
"xxxxxx1234xxxxxxxControl IDxxxxxx"
output:
"xxxxxx xxxxxxxControl IDxxxxxx"
thanks!
Scott
October 10, 2009, 7:33pm
2
Hi.
Using sed:
sed "s/\(.*\)....\(.\{7\}Control ID.*\)/\1 \2/" input_file
xxxxxx xxxxxxxControl IDxxxxxx
jbt828
October 12, 2009, 9:12am
4
Scott,
the command works ok, but 1 space replaces 4 bytes which compresses the file:
sed "s/\(.\)....\(.\{7\}Control ID. \)/\1 \2/"
In:
abcde****1234567Control ID890
to:
abcde 1234567Control ID890
need:
abcdebbbb1234567Control ID890
with b= space
Thanks!
Scott
October 12, 2009, 9:20am
5
Hi.
Add some spaces between \1 and \2
sed "s/\(.*\)....\(.\{7\}Control ID.*\)/\1 \2/" file2
xxxxxx xxxxxxxControl IDxxxxxx
jbt828
October 12, 2009, 11:12am
6
Thanks Scott! that worked..
---------- Post updated at 11:12 AM ---------- Previous update was at 09:26 AM ----------
when I try to run this on my production file it does not work. I think it's the file size or record length issue. Does sed have a limit for record lenght? should I try awk instead?
Scott
October 12, 2009, 11:21am
7
Hi.
No, it doesn't.
I just ran it on a file with a record (line) length of 750,000, and it worked fine.
Please state what the problem is (error message, etc.), and show what you did.
Thanks.
jbt828
October 12, 2009, 11:40am
8
no error messages. nothing happens, looks like it can't find 'Control ID".
When I run this on a small file it works. Could be end of line characters.. not sure.
Background:
This is a AFP file which I converted from ebcdic to ASCII.
when I do a "wc AFP.test1.ascii"
I receive 41 of these messages:
wc: AFP.test1.ascii:41: Invalid or incomplete multibyte or wide character
then...
40 606 10286 AFP.test1.ascii
Not sure if this helps or not.