read a line from a csv file and convert a column to all caps


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers read a line from a csv file and convert a column to all caps
# 1  
Old 12-31-2007
read a line from a csv file and convert a column to all caps

Hello experts,

I am trying to read a line from a csv file that contains '.doc' and print the second column in all caps.

e.g.

My csv file contains:
Test.doc|This is a Test|test1|tes,t2|test-3
Test2.pdf|This is a Second Test| test1|tes,t2|t-est3

while read line
do
echo "$line" | awk -F '|' '/.doc/ {print toupper($2)}'
done < $dataFile


output:
This is a Test


I've been trying to use the toupper function of awk but it does not convert to upper case.

Anyone know another way this can be done?


thanks
# 2  
Old 12-31-2007
Hate to tell you this, but it worked for me on an AIX box. I cut and paste your code as is.

Perhaps, if you are on Solaris, try nawk instead.

Wouldn't it be simpler to just do:

awk -F '|' '/[.]doc/ {print toupper($2)}' datafile
# 3  
Old 12-31-2007
Hi.

It worked for me as well:
Code:
#!/usr/bin/env sh

# @(#) a1       Demonstrate awk toupper function.

set -o nounset
echo

## Use local command version for the commands in this demonstration.

echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version bash awk

echo

# Use nawk or /usr/xpg4/bin/awk on Solaris.

cat >data1 <<'EOF'
Test.doc|This is a Test|test1|tes,t2|test-3
Test2.pdf|This is a Second Test| test1|tes,t2|t-est3
EOF

FILE=${1-data1}

echo
echo " Input file $FILE:"
cat $FILE

echo
echo " Results from awk:"
awk -F '|' '
/.doc/ {print toupper($2)}
' $FILE

exit 0

Producing:
Code:
% ./a1

(Versions displayed with local utility "version")
GNU bash 2.05b.0
GNU Awk 3.1.4


 Input file data1:
Test.doc|This is a Test|test1|tes,t2|test-3
Test2.pdf|This is a Second Test| test1|tes,t2|t-est3

 Results from awk:
THIS IS A TEST

Best wishes ... cheers, drl
# 4  
Old 12-31-2007
Hi again,


thanks for the feedback...I used nawk as suggested and it worked.

awk -F '|' '/[.]doc/ {print toupper($2)}' datafile

is definitely simpler than what I have...I'm a newbie to unix scripting so I of course made something more complicated than it should be

thanks for the help Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies

2. Shell Programming and Scripting

Column with New Line in CSV file

Hello, Got a CSV file which contains 21 columns Need to convert the file to Pipe delimiter and Few columns text data contains new line Example 1,2,3,"ABC" 8" ABC,5,6,7 1,2,3,"ABC" 8" ABC,5,6,7 ( New Line) 1,2,3,""ABC" 8" ABC", 5,6,7 1,2,3,"ABC" ,5,6,7(New line) Expected... (8 Replies)
Discussion started by: krux_rap
8 Replies

3. Shell Programming and Scripting

Convert a two-column list into a csv

Hi experts, I have a very large (1.5M lines), sorted but unstructured list that looks like this: process_nameA valueA process_nameA valueA ... process_nameB valueB process_nameB valueB ... process_nameN valueN I'd like to turn this into a csv. The values are all... (4 Replies)
Discussion started by: abercrom
4 Replies

4. Shell Programming and Scripting

awk read column csv and search in other csv

hi, someone to know how can i read a specific column of csv file and search the value in other csv columns if exist the value in the second csv copy entire row with all field in a new csv file. i suppose that its possible using awk but i m not expertise thanks in advance (8 Replies)
Discussion started by: giankan
8 Replies

5. Shell Programming and Scripting

convert huge .xml file in .csv with specific column.

I have huge xml file in server and i want to convert it to .csv with specific column ... i have search in blog but i didn't get any usefully command. Thanks in advance (1 Reply)
Discussion started by: pareshkp
1 Replies

6. UNIX for Dummies Questions & Answers

skip first line when doing a read of csv file

Folks, how do i skip the first line in a csv, while doing the read of a csv file in to a variable line by line. eg : do echo $line done < $rpt where rpt is path to csv file The initial 1st line is a garbage that i want to avoid, and start reading from 2nd line ... (2 Replies)
Discussion started by: venu
2 Replies

7. Shell Programming and Scripting

Remove line feed from csv file column

Hi All, i have a csv file . In the 7th column i have data that has line feed in it. Requirement is to remove the line feed from the 7th column whenever it appears There are 11 columns in the file C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,C11 The value in C7 contains line feed ( Alt + Enter ),... (2 Replies)
Discussion started by: r_t_1601
2 Replies

8. Shell Programming and Scripting

Remove line feed from csv file column

Hi All, My requirement is to remove line (3 Replies)
Discussion started by: r_t_1601
3 Replies

9. Shell Programming and Scripting

Read csv file line by line

Folks , i want to read a csv file line by line till the end of file and filter the text in the line and append everything into a variable. csv file format is :- trousers:shirts,price,50 jeans:tshirts,rate,60 pants:blazer,costprice,40 etc i want to read the first line and get... (6 Replies)
Discussion started by: venu
6 Replies

10. Shell Programming and Scripting

read file line by line print column wise

I have a .csv file which is seperated with (;) inputfile --------- ZZZZ;AAAA;BBB;CCCC;DDD;EEE; YYYY;BBBB;CCC;DDDD;EEE;FFF; ... ... reading file line by line till end of file. while reading each line output format should be . i need to print only specific columns let say 5th... (2 Replies)
Discussion started by: rocking77
2 Replies
Login or Register to Ask a Question