Cut the first column in listed files

1.give the command wc -l *e* > create2.txt

2.now create2.txt contains

a.txt
b.txt
c.txt
d.txt

3.create2.txt is a random file ( output may vary depends on time) (eg: a1.txt , b1.txt,c1.txt,d1.txt if time changes)

  1. now i want to cut the first colum from all the files mentioned in the create2.txt and save the value to example.txt

can you post the sample of the files? how they appear in the file.

a.txt contains

832423| jkhsdkjf67hkkjh|mkmdshnklj|l;kds|klndls
234234| lksdhgldf|lkshdfkpjsd|lskdnlfks|lskjdfg|
873298| jdhfkjsdh |jkhdkoj|kljdslk|

b.txt and c.txt also contains the same data's.

I need i have to cut the first row's first coloum data.

thanks for responce

Probably this will work.. if i understood it right...

for file in `cat create2.txt`
do
cut -d'|' -f1 $file >> firstcol.txt
done

Here i am reading hte list of files in loop and pushing hte first column in that file to firstco.txt. I am assuming delimiter is '|'.

A better way to read a file in a loop is:

while read file
do
  cut -d'|' -f1 "$file" >> firstcol.txt
done < create2.txt

Another one:

awk -F\| '{print $1}' create2.txt >> firstcol.txt

i'm getting the below error

Missing $ on loop variable at value.txt line 1.

Did u try this.

for file in `cat create2.txt`
do
cat ${file} |cut -d'|' -f1 >> firstcol.txt
done

sorry Aswin still getting the same error

Missing $ on loop variable at value.txt line 1.

Can you post the script u have written and the files u are processing with sample data.The same script worked when i tested here. Give the path for the files as well if they not in the same path from where u are executing the script.

#!/usr/bin/perl
for file in `cat create2.txt`
do
cat ${file} |cut -d'|' -f1 >> firstcol.txt
done

create2.txt cotains these details

50 allignment.pl

      
      13 |example.txt
       8 |exeout.txt
       8 |test3.txt
       3 |value.txt

and create2 .txt will get the inputs from running this commend wc -l *e* >create2.txt

Hey,

I was talking with respect to unix and not perl. I am not sure whether it will work in perl.

Also there seems to be a empty line in create2.txt. The first record doesnt have pipe as well.And the file name is column2 not col 1 .

If so try

for file in `cat create2.txt| cut -d'|' -f2`

dear adaleru,

If you don't mind, please be specific about your requirement.
from the previous posts, it is unclear about what you want.

  1. as per the Post #1, create2.txt has the following format,
a.txt
b.txt
c.txt
d.txt

as per the post #10, you are using this

      13 |example.txt
       8 |exeout.txt
       8 |test3.txt
       3 |value.txt

Please confirm this. or you want to cut the first field from all the rows.

  1. You want the first filed as the output or the rest of the fields?

  2. Can you use shell solutions or just Perl ?

ls > out_file

for line in out_file
do
cat $line | awk '{print $1}' $line >> result_file
done

this will work in unix not sure about perl.