To append two columns without double quotes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To append two columns without double quotes
# 1  
Old 03-31-2011
To append two columns without double quotes

Hi i have a file with follw data
Code:
"20090427","0","","16371311","-100200","","","","16371311","JUL","09"

In the 10th column i need to convert the month name into month number in this case JUL will be 7 and append the 10th and 11th column which shows me the output as 709. Can you suggest a shell script or which commands should i go for ,i tried doing awk and sed but not getting the desired output.

Last edited by Franklin52; 03-31-2011 at 09:24 AM.. Reason: Please use code tags
vee789
# 2  
Old 03-31-2011
Code:
$  ruby -F"," -rdate  -ane '$F[9]=Date.parse($F[9]).strftime("\"%m")+$F[10].chomp[1..-1];puts $F[0..-2].join(",")' file
"20090427","0","","16371311","-100200","","","","16371311","0709"

# 3  
Old 03-31-2011
Try:
Code:
perl -F"," -nlae 'BEGIN{%m=("JAN","1","FEB","2","MAR","3","APR","4","MAY","5","JUN","6","JUL","7","AUG","8","SEP","9","OCT","10","NOV","11","DEC","12")};$F[9]=~s/"//g;$F[10]=~s/"//g;print "$m{$F[9]}$F[10]"' file

# 4  
Old 03-31-2011
Sorry, i couldnt understand the logic, actually i need unix commands to get the output. I am currently using ksh Smilie

---------- Post updated at 07:43 AM ---------- Previous update was at 07:40 AM ----------

I tried this command awk '{print $10 $11}' FS="," test.txt | sed -e "s/JUL/7/g" but that gives me the output as "7""09" whereas i need only 709 without double quotes.

---------- Post updated at 07:46 AM ---------- Previous update was at 07:43 AM ----------

This command only goes if i consider july as the month
vee789
# 5  
Old 03-31-2011
You can run that Perl line in the command line...
# 6  
Old 03-31-2011
Hey thanks so much it worked.
vee789
# 7  
Old 03-31-2011
With awk:
Code:
awk -F\" '
{s=$22;sub("," FS $22 FS,"")}
{$20=sprintf(index("JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC",$20)+2)/3 s}
1' OFS=\" file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace double quotes inside the string data for all the columns

Please use code tags Hi, I have input data is below format and n of column in the multiple flat files. the string data has any double quotes(") values replaced to double double quotes for all the columns{""). Also, my input flat file each column string data has carriage of new line too.... (14 Replies)
Discussion started by: SSrini
14 Replies

2. UNIX for Beginners Questions & Answers

To remove double quotes from specific columns

Hi, I've a requirement like, in a csv file of 30+ fields where all the columns are having double quotes I need to remove the double quotes from certain fields and certain field should remain as it is. Eg:... (6 Replies)
Discussion started by: Krishnanth S
6 Replies

3. Shell Programming and Scripting

Need shell script to append double quotes for each column in a file

Hi Experts, I am beginner to the shell scripting, My requirement is to append double quotes for each column in a file if double quotes does not exist. Example: "abc"|123|"gh-ch"|23.067 Use code tags, thanks. (10 Replies)
Discussion started by: spidy
10 Replies

4. Shell Programming and Scripting

Extract multiple columns base on double quotes as delimiter

Hi All, I have my data like below "1","abc,db","hac,aron","4","5" Now I need to extract 1,2,4th columns Output should be like "1",abc,db","4" Am trying to use cut command but not able to get the results. Thanks in advance. (4 Replies)
Discussion started by: weknowd
4 Replies

5. Shell Programming and Scripting

Replace Double quotes within double quotes in a column with space while loading a CSV file

Hi All, I'm unable to load the data using sql loader where there are double quotes within the double quotes As these are optionally enclosed by double quotes. Sample Data : "221100",138.00,"D","0019/1477","44012075","49938","49938/15043000","Television - 22" Refurbished - Airwave","Supply... (6 Replies)
Discussion started by: mlavanya
6 Replies

6. Shell Programming and Scripting

Replace double quotes with a single quote within a double quoted string

Hi Froum. I have tried in vain to find a solution for this problem - I'm trying to replace any double quotes within a quoted string with a single quote, leaving everything else as is. I have the following data: Before: ... (32 Replies)
Discussion started by: pchang
32 Replies

7. Shell Programming and Scripting

Issue with Single Quotes and Double Quotes for prompt PS1

Hi, Trying to change the prompt. I have the following code. export PS1=' <${USER}@`hostname -s`>$ ' The hostname is not displayed <abc@`hostname -s`>$ uname -a AIX xyz 1 6 00F736154C00 <adcwl4h@`hostname -s`>$ If I use double quotes, then the hostname is printed properly but... (3 Replies)
Discussion started by: bobbygsk
3 Replies

8. UNIX for Dummies Questions & Answers

grep single quotes or double quotes

Unix superusers, I am new to unix but would like to learn more about grep. I am very familiar with regular expressions as i have used them for searching text files in windows based text editors. Since I am not very familiar with Unix, I dont understand when one should use GREP with the... (2 Replies)
Discussion started by: george_vandelet
2 Replies

9. Shell Programming and Scripting

Single quotes and double quotes

Hi guys, I have a sed line in double quotes which works fine, but I want it to be in single quotes here is the sed line sed "/abc_def/s/\'.*\'/\'\${abc_def}\'/" can some one give the equivalent to the above script in single quotes Thanks a ton (5 Replies)
Discussion started by: sol_nov
5 Replies

10. Shell Programming and Scripting

Double quotes or single quotes when using ssh?

I'm not very familiar with the ssh command. When I tried to set a variable and then echo its value on a remote machine via ssh, I found a problem. For example, $ ITSME=itsme $ ssh xxx.xxxx.xxx.xxx "ITSME=itsyou; echo $ITSME" itsme $ ssh xxx.xxxx.xxx.xxx 'ITSME=itsyou; echo $ITSME' itsyou $... (3 Replies)
Discussion started by: password636
3 Replies
Login or Register to Ask a Question