how to convert this to a loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to convert this to a loop
# 1  
Old 11-26-2010
how to convert this to a loop

I have a list of files in the same directory need to do the following

Code:
cut -d "=" f2 file1 > file1_result
cut -d "=" f2 file2 > file2_result
...

past file1_result file2_result .... >file_sum

How to do this in a loop? Thank you.

Last edited by vbe; 11-26-2010 at 12:22 PM.. Reason: code tags please
# 2  
Old 11-26-2010
Do you mean:
Code:
cut -d "=" -f2 file1 > file1_result
cut -d "=" -f2 file2 > file2_result
...

paste file1_result file2_result .... >file_sum

What is the maximum number of input files ?
Is there any way that the files called file* can be in a different directory from the files called file*_result ?
# 3  
Old 11-26-2010
Yes, you are right with the red colored correction.

total input files is about 10-20 files

Yes, file* can be in different directory for file*_result.

Do you have any idea how to proceed using loop? Thanks a lot
# 4  
Old 11-26-2010
Code:
mkdir output
for FILE in input/*
do
        # Strip input/ from FILE to make OUTNAME
        OUTNAME=$(basename "$FILE")
        # Cut reading from $FILE writing to output/${OUTNAME}
        cut -d "=" f2 "$FILE" > "output/${OUTNAME}"
done

paste output/* > file_sum

This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert values in an array using a loop

I have a headerless array of 1000 columns x 100000 rows. The array only contains 4 values; 0/0, 0/1, 1/1, ./. Here I am showing the 1st 3 rows and columns of the input array 0/0 0/0 1/1 0/1 0/1 0/1 0/0 ./. 0/0 0/0 0/0 0/0 I would like to convert the values in... (9 Replies)
Discussion started by: Geneanalyst
9 Replies

2. Shell Programming and Scripting

Loop to convert text output in the HTML format

Hello Everyone, I have a sample file raw.txt as shown below : Drive Bays Bay Name : SD-2C Number of Standby Power Supplies : 4 Number of Drive Enclosures : 12 Summary Status of Contained Modules All... (6 Replies)
Discussion started by: rahul2662
6 Replies

3. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies

4. Homework & Coursework Questions

Loop to Convert a list from an input file and output it to another file

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: A) Write a script, which will take input from a file and convert the number from Centigrade to Fahrenheit... (5 Replies)
Discussion started by: AliTheSnake
5 Replies

5. Shell Programming and Scripting

Array Variable being Assigned Values in Loop, But Gone when Loop Completes???

Hello All, Maybe I'm Missing something here but I have NOOO idea what the heck is going on with this....? I have a Variable that contains a PATTERN of what I'm considering "Illegal Characters". So what I'm doing is looping through a string containing some of these "Illegal Characters". Now... (5 Replies)
Discussion started by: mrm5102
5 Replies

6. Shell Programming and Scripting

Loop through directory convert jpg to png

Hi guys. I will be frequently needing to convert .jpg files to 183x183 .png thumbnails. I can't quite seem to wrap my head around how to make a for loop to do this. With the help of my friend (who may have mislead me, I'm quite confused) I've got this. This is bash the command is: pngify... (3 Replies)
Discussion started by: Drayol
3 Replies

7. Shell Programming and Scripting

How to use loop to convert a DML statement into DDL?

Hi Unix Gurus, I am a newb. I am creating a script which will use an input file. This input file can have 1 or more than 1 DML staments like INSERT/DELETE/UPDATE. I have to execute these statements using my script but before execution of these DML statements, I need to check the count for... (17 Replies)
Discussion started by: ustechie
17 Replies

8. Shell Programming and Scripting

Using variables created sequentially in a loop while still inside of the loop [bash]

I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends. As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

9. Shell Programming and Scripting

Convert Text within multipul files - for loop

Is this possible? #!/bin/ksh for file in `*.idlesince` do while read inter time do printf "%s %s\n" "${inter}" "$(perl -e 'print scalar localtime('"${time}"') . "\n";')" >> "${file}.done" done < "${file}" done The error I get is line 9: router.idlesince: command not... (1 Reply)
Discussion started by: mrlayance
1 Replies

10. Shell Programming and Scripting

here-doc convert 2 script convert to single script?

I have my main script calling another script to retrive a "ls -alt" of a directory that's located in a remote location I'm sftping into. main.sh #!/bin/ksh getLS.sh > output.txt getLS.sh #!/bin/sh /home<..>/sftp <host@ip> <<! cd /some/dir/Log ls -alt quit ! Basically I'd like to be... (2 Replies)
Discussion started by: yongho
2 Replies
Login or Register to Ask a Question