sed *.csv from file > newfile with /n


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed *.csv from file > newfile with /n
# 1  
Old 02-27-2009
sed *.csv from file > newfile with /n

I have a an output file with a format:

something blah1.csv blah2.csv blah3.csv somethingelse

and I'm trying to use sed to pull all the *.csv entries out and put them 1 per line on a new file. I can't quite figure out how to write them to a new file with carriage returns, is there a simple way to do this?
# 2  
Old 02-27-2009
ls *.csv > file.txt

This should work.
# 3  
Old 02-27-2009
but all of the csv entries I'm interested in are in the same file separated by a single space, will ls work for this?

I've managed to get awk to see the csv's by doing

Code:
awk '/csv/ { print $0 }' somefile > somenewfile

but basically all that does is cat the contents of somefile to somenewfile

Last edited by unclecameron; 02-27-2009 at 05:28 AM..
# 4  
Old 02-27-2009
Code:
$ cat file
something blah1.csv blah2.csv blah3.csv somethingelse
something blah10.csv blah20.csv blah300.csv somethingelse
something blah100.csv blah200.csv blah300.csv somethingelse
$ list=$(cat file)
$ for i in $list
> do
> echo $i | grep \.csv$ >> file2
> done
$ cat file2
blah1.csv
blah2.csv
blah3.csv
blah10.csv
blah20.csv
blah300.csv
blah100.csv
blah200.csv
blah300.csv
$

# 5  
Old 02-27-2009
Code:
a="a b c.csv d.abc e.csv f"
echo $a | awk 'BEGIN{RS=" "}/.csv$/{printf("%s ",$1)}'

# 6  
Old 02-27-2009
grep ".csv" inputfile > outputfile

Sorry i had wrongly read it has folder
# 7  
Old 02-27-2009
wow, thanks for all the help! I got Goldorakk's solution to work, but I want to understand awk better, chihung can you explain a little bit of what exactly awk is doing, I really am trying to understand this so I can solve my own problems later, not just cut/paste Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

What does the sed command here exactly doing to csv file?

I have the following csv file at the path; now using sed command. what is this exactly doing. sed -i 's//,/g' /FTP/LAB_RESULT_CM.csv Thank you very much for the helpful info. (2 Replies)
Discussion started by: cplusplus1
2 Replies

2. Shell Programming and Scripting

Combined sed+awk for lookup csv file

have written a combined sed+awk to perform a lookup operation which works but looking to enhance it. looking to match a record using any of the comma separated values + return selected fields from the record - including the field header. so: cat foo make,model,engine,trim,value... (6 Replies)
Discussion started by: jack.bauer
6 Replies

3. Shell Programming and Scripting

Transposing lines in a csv file with sed

Hi I have a large csv file with lines like below Date,Status,orig,dest,in,out,when,where 2012-01-01 00:30:37,I,48,56,23,98,83,34 2012-06-17 15:00:38,I,72,43,12,65,34,12I will really appreciate if someone can help with a sed script to transpose this to 2012-01-01 00:30:37,I,orig,48... (5 Replies)
Discussion started by: kaf3773
5 Replies

4. Shell Programming and Scripting

Converting txt file into CSV using awk or sed

Hello folks I have a txt file of information about journal articles from different fields. I need to convert this information into a format that is easier for computers to manipulate for some research that I'm doing on how articles are cited. The file has some header information and then details... (8 Replies)
Discussion started by: ksk
8 Replies

5. Shell Programming and Scripting

splitting newfile.txt file and executing each splitted files

split -l $split_count newfile.txt for i in $split_files* do if test -s $workingdir/$split_files* then ./<$i.out> fi done ... (4 Replies)
Discussion started by: sanjay mn
4 Replies

6. Shell Programming and Scripting

awk/sed/something else for csv file

Hi, I have a filename.csv in which there are 3 colums, ie: Name ; prefixnumber ; number root ; 020 ; 1234567 user1,2,3 ; 070 ; 7654321 What I want is to merge colum 2 and 3 that it becomes 0201234567 or even better +31201234567 so the country number is used and drop the leading 0.... (9 Replies)
Discussion started by: necron
9 Replies

7. Shell Programming and Scripting

Using awk/sed in handling csv file.

Please study the below script and the output Script: echo "Minimum ${host} ${process} response time=${min} ms" >> ${OUTDIR}/${OUTFILE}; echo "Maximum ${host} ${process} response time=${max} ms" >> ${OUTDIR}/${OUTFILE}; echo "Average ${host} ${process} response time=${avg} ms" >>... (0 Replies)
Discussion started by: ajincoep
0 Replies

8. Shell Programming and Scripting

Parsing complicated CSV file with sed

Yes, there is a great doc out there that discusses parsing csv files with sed, and this topic has been covered before but not enough to answer my question (unix.com forums). I'm trying to parse a CSV file that has optional quotes like the following: "Apple","Apples, are fun",3.60,4.4,"I... (3 Replies)
Discussion started by: analog999
3 Replies

9. Shell Programming and Scripting

Remove text from a csv file using sed

I am trying to remove the ita from this file: "1234ita","john","smith" "56789ita","jim","thomas" the command i am using is: sed '/^ita/d' infile.csv > outfile.csv it is running but doing nothing, very rarely use sed so trying to learn it any help would be appreciated (2 Replies)
Discussion started by: Pablo_beezo
2 Replies

10. Shell Programming and Scripting

How to compare 2 file to newfile......

Hi all Member i want compare 2 file to newfile I am new to shell script, just wanted you guy to help. example file A CM-00000BN_Oth-VAS-0000392 CM-00000BNSEED_Oth-Spe-0000392 CM-00000KJ_Pos-Pro-0000806 CM-00000KJ_Pos-Pro-0000810 CM-00000KJ_Pos-Pro-0000812 CM-00000KJ_Pos-Pro-0000814... (1 Reply)
Discussion started by: ooilinlove
1 Replies
Login or Register to Ask a Question