The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-27-2008
yonhk yonhk is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 5
Awk help

Hi all,

I cut specific cell(row=2, column=1) in my excel file and created new file using following script.

awk -F"," 'NR ==2 {print $1}' file1.csv > file1_new.csv

awk -F"," 'NR ==2 {print $1}' file2.csv > file2_new.csv

and so on....

The problem is that I have thousand files and I have to do the same procedure thousand times.

How can I make this simple using loop command?

Thanks in advance.
  #2 (permalink)  
Old 10-27-2008
freelong freelong is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 38
I did not test this one, but you can do it:

Code:
for file in *.csv
do
    awk -F"," 'NR==2 {print $1}' ${file} > ${file}_new
done

  #3 (permalink)  
Old 10-27-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,441
Quote:
Originally Posted by freelong View Post
I did not test this one, but you can do it:

Code:
for file in *.csv
do
    awk -F"," 'NR==2 {print $1}' ${file} > ${file}_new
done
This should work:

Code:
...
    awk -F"," 'NR==2 {print $1}' ${file} > ${file%.*}_new.cvs
...

  #4 (permalink)  
Old 10-29-2008
yonhk yonhk is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 5
Thanks a lot!!!!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:51 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0