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
# 8  
Old 07-06-2010
Quote:
Originally Posted by ashwin3086
Did u try this.

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

sorry Aswin still getting the same error

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

# 9  
Old 07-06-2010
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.
# 10  
Old 07-06-2010
Code:
#!/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
Code:
      
      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

Last edited by Scott; 07-06-2010 at 08:46 AM.. Reason: Code tags, please...
# 11  
Old 07-06-2010
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
Code:
for file in `cat create2.txt| cut -d'|' -f2`


Last edited by ashwin3086; 07-06-2010 at 08:44 AM.. Reason: changed the explanantion
# 12  
Old 07-06-2010
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,
Code:
a.txt
b.txt
c.txt
d.txt

as per the post #10, you are using this

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


2.
Quote:
i have to cut the first row's first coloum data.
Please confirm this. or you want to cut the first field from all the rows.

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

4. Can you use shell solutions or just Perl ?
# 13  
Old 07-06-2010
Code:
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.
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