LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-18-2008, 04:51 PM   #1
michael_nc
LQ Newbie
 
Registered: Apr 2008
Posts: 1

Rep: Reputation: 0
"for" loop with awk


Hi, I am new to linux and awk, and am trying to run a script that will execute an awk command that deletes the first column of a file for every file in a directory.

I think it should look like this:

for i in *; do awk '{$1=""}1' $i > $i_done.txt; done

When I run this it finished, but I don't get any new output files, only one file called ".txt" which appears to have all the results in it.

But when take the command out of the for loop and just run it on one file, it works exactly as it should.

I am using Cygwin on a windows box.

Any help appreciated.

Thanks,

Mike
 
Old 04-18-2008, 04:57 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
You're using a variable which is not assigned:
Code:
> $i_done.txt
this uses a variable called "i_done". It should be
Code:
> ${i}_done.txt
note that the dot is not included in the variable name (and so the following text) whereas the underscore is.
 
Old 04-18-2008, 05:12 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Hi,
And welcome to LQ!

And a sed alternative that saves you the loop...

Code:
sed -r -iori 's/^[^ \t]+[^ \t](.*)/\1/' *
Admittedly the regex may look a tad daunting ;}


Cheers,
Tink

Last edited by Tinkster; 04-18-2008 at 05:24 PM. Reason: make back-up copy
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
awk question on handling *.CSV "text fields" in awk jschiwal Programming 8 05-27-2010 06:23 AM
Sed/Awk: print lines between n'th and (n+1)'th match of "foo" xaverius Programming 17 08-20-2007 11:39 AM
Replacing "function(x)" with "x" using sed/awk/smth Griffon26 Linux - General 3 11-22-2006 10:47 AM
awk "for loop" question rharvey@cox Programming 5 05-03-2006 06:12 AM
how can I invoke "awk" from shell to do floating point math? Joseph Schiller Programming 8 01-12-2006 05:00 AM


All times are GMT -5. The time now is 08:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration