User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 456,432 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,604 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 2737 | Replies: 2
Reply
Join Date: Aug 2007
Posts: 2
Reputation: damanjit is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
damanjit damanjit is offline Offline
Newbie Poster

Question korn shell script_for loop

  #1  
Aug 8th, 2007
for i in table1 table2 table3 table4
do
perl -ne 's/ *\|/\|/g; print' ${AHS_DATA}/${i} > ./${i}.dat
done


what does perl -ne 's/ *\|/\|/g; print' ${AHS_DATA}/${i} > ./${i}.dat means??
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2007
Location: Aptos, CA
Posts: 118
Reputation: ft3ssgeek is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 7
ft3ssgeek's Avatar
ft3ssgeek ft3ssgeek is offline Offline
Junior Poster

Re: korn shell script_for loop

  #2  
Aug 17th, 2007
The experts here will correct and berate me if I am wrong, but while I don't under stand what the
's/ *\|/\|/g;
code means, the entire line of
perl -ne 's/ *\|/\|/g; print' ${AHS_DATA}/${i} > ./${i}.dat 
Appears to calculate the variable AHS_DATA divided by the variable i and outputs the result to i.dat...
This statement:
's/ *\|/\|/g;
appears to be some formatting instructions, but don't take my word on it...
Reply With Quote  
Join Date: Feb 2006
Posts: 1,509
Reputation: masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light 
Rep Power: 10
Solved Threads: 136
masijade's Avatar
masijade masijade is offline Offline
Posting Virtuoso

Re: korn shell script_for loop

  #3  
Aug 17th, 2007
-n means suppress output (i.e. read the lines in the file, but don't output them).

s/ *\|/\|/g; means replace all occurrences of of zero or more whitespace followed ba a "|" (i.e. "|", or " |", or " |") with "|".

And the print after that means output the lines where the "command" actually did anything (i.e. any line that did not have any occurrences of "|" will not be output).

${AHS_DATA} is a variable holding a directory name.

${i} is the variable from the loop (table1 or table2 or table3 etc), and references a file of that name in the above directory. sed will read this file for the "lines" of input referenced above.

> ./${i}.dat means that all output should go into a file in the currect directory called table1.dat (or table2.dat, or table3.dat, etc, depending on the value of ${i})
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Shell Scripting Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 1:28 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC