Computing.Net > Forums > Unix > unix for modifying fields

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

unix for modifying fields

Reply to Message Icon

Name: htnkd
Date: August 8, 2005 at 07:09:46 Pacific
OS: linux
CPU/Ram: 2.2
Comment:

I have a file with thousands of records.
Example:
xxxx|ccccc|County kkkk|oo|ppppp|pppppppp
xxxx|ccccc|(County) kkkk|oo|ppppp|pppppppp

I need County, (County) removed from field 3 in this example.

so it should read as follow:

xxxx|ccccc|kkkk|oo|ppppp|pppppppp
xxxx|ccccc|kkkk|oo|ppppp|pppppppp

new to this if you can help me I would appreciate this in a unix script

thanks




Sponsored Link
Ads by Google

Response Number 1
Name: Luke Chi
Date: August 8, 2005 at 08:36:00 Pacific
Reply:

Input (input.txt):

sed 's/[()*Country[)]* //g' input.txt

Luke Chi


0

Response Number 2
Name: Jim Boothe
Date: August 8, 2005 at 09:35:44 Pacific
Reply:

That sed could delete all sorts of data, such as any of those letters followed by a space, and from anywhere in the line.

This awk will delete only from word 3:

awk -F\| 'BEGIN{OFS="|"}{sub("[(]*County[)]* ","",$3);print}'


0

Response Number 3
Name: htnkd
Date: August 12, 2005 at 11:54:11 Pacific
Reply:

I need it to work for field 3- not word 3

the word could be anywhere in field 3 - field1, field 2, field4 etc.. should not be affected by it.

for example:

sss sss s|sssss|ssss (Country)|sss sss
xxxx xx|xxx xxxx|Country xxxx| xxxx xx

need so look like this when done
sss sss s|sssss|ssss|sss sss
xxxx xx|xxx xxxx|xxxx| xxxx xx

thanks for your help in advance


0

Response Number 4
Name: Luke Chi
Date: August 16, 2005 at 12:38:50 Pacific
Reply:

awk -F\| 'BEGIN{OFS="|"}{sub("[ ]*[(]*Country[)]*[ ]*","",$3);print}' input.txt

Luke Chi


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: unix for modifying fields

Shell script for Text file parsing www.computing.net/answers/unix/shell-script-for-text-file-parsing/4388.html

unix for editing www.computing.net/answers/unix/unix-for-editing/6556.html

Unix for loop www.computing.net/answers/unix/unix-for-loop/3717.html