Cut the first column in listed files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cut the first column in listed files
# 1  
Old 07-06-2010
Question Cut the first column in listed files

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

2.now create2.txt contains

Code:
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)

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

Last edited by Scott; 07-06-2010 at 08:42 AM..
# 2  
Old 07-06-2010
can you post the sample of the files? how they appear in the file.
# 3  
Old 07-06-2010
Quote:
Originally Posted by anchal_khare
can you post the sample of the files? how they appear in the file.
a.txt contains

Code:
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

Last edited by Scott; 07-06-2010 at 08:43 AM..
# 4  
Old 07-06-2010
Probably this will work.. if i understood it right...

Code:
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 '|'.
# 5  
Old 07-06-2010
Quote:
Originally Posted by ashwin3086
Probably this will work.. if i understood it right...

Code:
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:
Code:
while read file
do
  cut -d'|' -f1 "$file" >> firstcol.txt
done < create2.txt

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

# 6  
Old 07-06-2010
Quote:
Originally Posted by ashwin3086
Probably this will work.. if i understood it right...

Code:
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 '|'.
i'm getting the below error

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

# 7  
Old 07-06-2010
Did u try this.

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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Want to delete the junk files from a directory which are not listed in a TEXT file

Hello Everyone, I want to delete the image files from a directory, which are not listed in a TEXT file. The directory contains large number of image files (in millions) required / not required. I want to delete the image files which are "not required". I have generated a Text file having... (3 Replies)
Discussion started by: Praveen Pandit
3 Replies

2. Shell Programming and Scripting

Delete files listed in text file

Hi Team, Here's the scenario, I have a text file called "file_list.txt". Its content is as follows. 111.tmp 112.tmp 113.tmp 114.tmp These files will present in "workdir" directory. It has many files. But only the files present in file_list.txt has to be deleted from the workdir... (7 Replies)
Discussion started by: kmanivan82
7 Replies

3. Shell Programming and Scripting

Total number of files in the folder should be listed

Hi All, When i give the ls -lrt to list out all files with total number of files , i get the output as ls -lrt total 72 -rw-r--r-- 1 hari staff 796 Jul 11 09:17 va.txt -rw-r--r-- 1 hari staff 169 Jul 13 00:20 a.log -rwxr-xr-x 1 hari staff 659 Aug... (9 Replies)
Discussion started by: Kalaihari
9 Replies

4. Shell Programming and Scripting

Capture listed files from find command

Hi all, I am using command find $InputPath -type f -mtime +30 However, I need to capture the file listed in screen. May I know how to achieve this? Thank you. (12 Replies)
Discussion started by: ashly
12 Replies

5. Shell Programming and Scripting

Pick the column value based on another column using awk or CUT

My scenario is that I need to pick value from third column based on fourth column value, if fourth column value is 1 then first value of third column.Third column (2|3|4|6|1) values are cancatenated. Please someone help me to resolve this issue. Source column1 column2 column3 column4... (2 Replies)
Discussion started by: Ganesh L
2 Replies

6. Shell Programming and Scripting

Copy files listed in text file to new directory

I am trying to write a script that will copy all file listed in a text file (100s of file names) to a new directory Assume script will run with main as current working directory and I know how many files/lines will be in List.txt Im trying to work up a test script using this model Contents of... (2 Replies)
Discussion started by: IAmTheGrass
2 Replies

7. Shell Programming and Scripting

Files copying - [ Listed files alone. ] - Shell script

Hi All, I am doing this for svn patch making. I got the list of files to make the patch. I have the list in a file with path of all the files. To Do From Directory : /myproject/MainDir To Directory : /myproject/data List of files need to copy is in the file: /myproject/filesList.txt ... (4 Replies)
Discussion started by: linuxadmin
4 Replies

8. Shell Programming and Scripting

Cut the first column in listed files > PERL script

Hi All, Using this command wc -l *e* > create2.txt i'm getting the following output >>>create2.txt listed output files, my requirement is how to cut the first coloum in all the files mentioned in create2.txt in perl. 50 allignment.pl 3 create.txt 4 application.txt ... (8 Replies)
Discussion started by: adaleru
8 Replies

9. Shell Programming and Scripting

Shellscript to sort duplicate files listed in a text file

I have many pdf's scattered across 4 machines. There is 1 location where I have other Pdf's maintained. But the issues it the 4 machines may have duplicate pdf's among themselves, but I want just 1 copy of each so that they can be transfered to that 1 location. What I have thought is: 1) I have... (11 Replies)
Discussion started by: deaddevil
11 Replies

10. HP-UX

CVSWeb - Directories listed but files not listed

I am using CVSWeb on HPUnix. When i access it, all directories are listed but files are not listed. I am getting the error "NOTE: There are 51 files, but none matches the current tag. " in tomcat sevrer log i am getting the message "rlog warning: Missing revision or branch number after -r"... (0 Replies)
Discussion started by: ganesh
0 Replies
Login or Register to Ask a Question