Computing.Net > Forums > Unix > Unix awk

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Unix awk

Reply to Message Icon

Name: Yoon
Date: October 27, 2008 at 11:34:33 Pacific
OS: Linux
CPU/Ram: 8GB
Product: IBM
Comment:

Hello 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.



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: October 27, 2008 at 12:06:22 Pacific
Reply:

Provided in your current directory that all of your datafiles end with a csv extension:

#!/bin/bash

# untested
for nm in *.csv
do
nfile=$(basename "$nm" .csv)
nfile="${nfile}_new.csv"
awk ... "$nm" > "$nfile"
done



0

Response Number 2
Name: dpminusa
Date: November 2, 2008 at 14:44:16 Pacific
Reply:

You may want to try Perl as your scripts get more advanced. It is on most Linux/UNIX systems shipped.

perldoc perl from the command line.

Perl was inspired by awk in the 80's. Larry Wall of NASA is the original author. UNIX/Linux is its home turf.

Web Developer


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Unix awk

unix awk printf www.computing.net/answers/unix/unix-awk-printf/6272.html

Unix Awk www.computing.net/answers/unix/unix-awk/7727.html

retrieve text between two strings www.computing.net/answers/unix/retrieve-text-between-two-strings-/8136.html