Script required (Example of a Bad Forum Subject)


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Script required (Example of a Bad Forum Subject)
# 1  
Old 02-04-2010
Script required (Example of a Bad Forum Subject)

A file contains the following data

Code:
Name, Age, Sex, city, country
abc, 20, m, tokyo, Japan
def, 21, f, sydney, Australia
ghd, 23, m, chicago, USA
rww, 29, f, london, UK

I need the city column to be replaced with XXX as follows

Code:
Name, Age, Sex, city, country
abc, 20, m, XXX, Japan
def, 21, f, XXX, Australia
ghd, 23, m, XXX, USA
rww, 29, f, XXX, UK

Can you please provide a shell script that AIX supports ASAP

Last edited by Scott; 02-04-2010 at 05:14 PM.. Reason: Please use code tags
# 2  
Old 02-04-2010
Code:
awk -F, -v OFS=, 'NR > 1 && $4 = " XXX"' file

edit: oops, forgot about the header
Code:
awk -F, -v OFS=, 'NR==1; NR > 1 && $4 = " XXX"'


Last edited by Scott; 02-04-2010 at 05:37 PM..
# 3  
Old 02-04-2010
I have 2 requirements.

FIRST REQUIREMENT:

IT HAS + as DELIMITER AND " AS TEXT SEPERATOR. PLEASE SEE THAT THERE IS NO " BEFORE THE FIRST COLUMN. ALSO IT HAS DELIMITER VALUE AT THE END.
Code:
1232+"32"+"932"+"BLUE"+"BOX"+"23"+
1234+"32"+"933"+"RED"+"CAN"+"24"+
1233+"32"++"RED"+"CAN"+"24"+

OUTPUT SHOULD BE SUCH THAT THE 4 and 5 columns are read and replaced with XXX.

Code:
1232+"32"+"932"+"XXX"+"XXX"+"23"+
1234+"32"+"933"+"XXX"+"XXX"+"24"+
1233+"32"++"XXX"+"XXX"+"24"+

SECOND REQUIREMENT:
IT HAS + as DELIMITER AND " AS TEXT SEPERATOR
Code:
 
"LP232"+"40"+"932"+"GREEN"+"PEN"+"23"
"LP1234"+"44"+"933"+"RED"+"PENCIL"+"24"
"LP23"++"920"+"YELLOW"+"KNIFE"+"23"

OUTPUT SHOULD BE SUCH THAT THE 5 and 6 columns are read and replaced with XXX.
Code:
"LP232"+"40"+"932"+"436U"+"XXX"+"XXX"+"23"
"LP1234"+"44"+"933"+"82JK"+"XXX"+"XXX"+"24"
"LP23"++"920"+"XXX"+"XXX"+"23"

Can you please answer these questions. Many thanks
# 4  
Old 02-04-2010
If THESE ARE THE QUESTIONS you wanted answered, WHY DIDN'T YOU ASK THEM originally?
# 5  
Old 02-04-2010
I just got the changed requirement. Initially I was told that the files would be of the first posted format. But later files of the latest 2 formats have come!!
Sorry to bother you.
# 6  
Old 02-04-2010
Your sample data and expected output for the SECOND REQUIREMENT doesn't make any sense...

Where does that in red come from?
Code:
"LP232"+"40"+"932"+"436U"+"XXX"+"XXX"+"23"
"LP1234"+"44"+"933"+"82JK"+"XXX"+"XXX"+"24"
"LP23"++"920"+"XXX"+"XXX"+"23"

# 7  
Old 02-04-2010
I am sorry, in a hurry, i mentioned the last column incorrectly.
Code:
"LP232"+"40"+"932"+"GREEN"+"PEN"+"23"
"LP1234"+"44"+"933"+"RED"+"PENCIL"+"24"
"LP23"++"920"++"YELLOW"+"KNIFE"+"23"

OUTPUT IS
Code:
"LP232"+"40"+"932"+"436U"+"XXX"+"XXX"+"23"
"LP1234"+"44"+"933"+"82JK"+"XXX"+"XXX"+"24"
"LP23"++"920"++"XXX"+"XXX"+"23"

 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bad status in UNIX Script

Hello, sorry for my questions about that below script but i have an error that i don't understand. It seems that my find command is not working fine but for me the command is ok Thanks for your help ===================================== /usr/IBM/HTTPServer/apache_cache... (4 Replies)
Discussion started by: steiner
4 Replies

2. Shell Programming and Scripting

Bad substitution error in shell script

I have script data.sh which has following error. Script Name : data.sh #!/bin/sh infile=$1 len=${#infile} echo $len texfile=${infile:0:$len-4} echo $texfile run command ./data.sh acb.xml I get following error message: (5 Replies)
Discussion started by: man4ish
5 Replies

3. Shell Programming and Scripting

Why I get bad bad substitution when using eval?

Why I get bad replace when using eval? $ map0=( "0" "0000" "0") $ i=0 $ eval echo \${map$i} 0000 $ a=`eval echo \${map$i}` !!!error happens!!! bash: ${map$i}: bad substitution How to resolve it ? Thanks! (5 Replies)
Discussion started by: 915086731
5 Replies

4. Solaris

"Solaris" - A very good example of a very bad subject title

Any body known this command uadmin 2 (2 Replies)
Discussion started by: Rajesh_Apple
2 Replies

5. Linux

This forum's font looks bad on my new installation

Some forums, including this one, look bad in FireFox on my new installation of Arch. Or more specifically, the main font looks bad. I had the exact same problem on Fedora a few years ago when I did a new installation. I thought I rememberered that the solution there was to install some Lucida... (0 Replies)
Discussion started by: KenJackson
0 Replies

6. Shell Programming and Scripting

bad interpreter when running script

Hi All, I'm not confortable in writing script, can someone can help me, when I run that script below i found this error code : -bash: ./script.sh: /bin/sh.: bad interpreter: Here is the script for i in * x=${i##*.} z=$(perl -e 'print time;') t=$(echo $z-$x|bc)... (12 Replies)
Discussion started by: bzb23
12 Replies

7. Shell Programming and Scripting

Behavior of Bad Script in Cron Job

Hi A Ksh script is deployed in a server and executed through cronjob. If one of the line in the middle of the script fails . Are the remaining lines executed ? (3 Replies)
Discussion started by: Sivaswami
3 Replies

8. Shell Programming and Scripting

Script to search a bad record in a file then put the record in the bad file

I need to write a script that can find a bad record (for example: there is date field colom but value provided in the file for this field is N/A) then script shoud searches this pattern and then insert the whole record into the bad file. Example: File1 Name designation dateOfJoining... (2 Replies)
Discussion started by: shilendrajadon
2 Replies

9. UNIX for Advanced & Expert Users

Script to search a bad record in a file then put the record in the bad file

I need to write a script that can find a bad record (for example: there is date field colom but value provided in the file for this field is N/A) then script shoud searches this pattern and then insert the whole record into the bad file. Example: File1 Name designation dateOfJoining... (1 Reply)
Discussion started by: shilendrajadon
1 Replies
Login or Register to Ask a Question