Extracts files names and write those to another file in different directory


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Extracts files names and write those to another file in different directory
# 8  
Old 06-19-2012
OK, try:
Code:
awk -F\| 'NF==3{close(f); f=dir"/"$NF; next} {print>f}' dir="path/to/dir" file

# 9  
Old 06-19-2012
Scrutinizer thats awesome.. i need to learn awk..
# 10  
Old 06-19-2012
Hi Scrutinizer , it s moving the files names to other locations but when i open the file to view data it is saying no such file or directory

---------- Post updated at 02:13 PM ---------- Previous update was at 02:08 PM ----------

Code:
if [ -f test.fs ];
then
rm -f test.fs
else
touch test.fs
fi
cat inputfile.txt| while read line
do
test=`echo $line | grep 'abc' | cut -f1 -d'|'`
if [ "$test" == 'abc' ];
then
fname=`echo $line | grep 'abc' | cut -f3 -d'|'`
printf "${fname} \n" >> test.fs
mv current_directory/test.fs  target_directory
echo $line>>$fname
fi
done

but with this i am able to movie all the files to file.fs but it also writing the files in the current directory...i dont want these files to be in current directory...

Last edited by Scrutinizer; 06-19-2012 at 03:28 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Directory containing files,Print names of the files in the directory that are exactly same content.

Given a directory containing say a few thousand files, please output a list of all the names of the files in the directory that are exactly the same, i.e. have the same contents. func(a_directory_name) output -> {“matches”: , ... ]} e.g. func(“/home/my/files”) where the directory... (7 Replies)
Discussion started by: anuragpgtgerman
7 Replies

2. Shell Programming and Scripting

Compare Only "File Names" in 2 Files with file lists having different directory structure

I have a tar arcive arch_all.tar.gz and 4 batched tar archive . These batches are supposed to have all the files form arch1.all.tar.gz arch1_batch1.tar.gz arch1_batch2.tar.gz arch1_batch3.tar.gz arch1_batch4.tar.gz my issue is that the directory structure in "arch_all.tar.gz" is... (6 Replies)
Discussion started by: sumang24
6 Replies

3. Shell Programming and Scripting

How to list files names and sizes in a directory and output result to the file?

Hi , I'm trying to list the files and output is written to a file. But when I execute the command , the output file is being listed. How to exclude it ? /tmp file1.txt file2.txt ls -ltr |grep -v '-' | awk print {$9, $5} > output.txt cat output.txt file1.txt file2.txt output.txt (8 Replies)
Discussion started by: etldeveloper
8 Replies

4. Shell Programming and Scripting

Remove all files with specific file names in directory

If I have 5 files in a directory, what is the best way to remove specific files in it? For example, snps.ivg probes.ivg Desired output probes.ivg probes.txt all.txt Basically, removing those files with "snp" in the filename regardless of extension. Thank you :). (2 Replies)
Discussion started by: cmccabe
2 Replies

5. Shell Programming and Scripting

Exclude certain file names while selectingData files coming in different names in a file name called

Data files coming in different names in a file name called process.txt. 1. shipments_yyyymmdd.gz 2 Order_yyyymmdd.gz 3. Invoice_yyyymmdd.gz 4. globalorder_yyyymmdd.gz The process needs to discard all the below files and only process two of the 4 file names available ... (1 Reply)
Discussion started by: dsravanam
1 Replies

6. Shell Programming and Scripting

How to count number of files in directory and write to new file with number of files and their name?

Hi! I just want to count number of files in a directory, and write to new text file, with number of files and their name output should look like this,, assume that below one is a new file created by script Number of files in directory = 25 1. a.txt 2. abc.txt 3. asd.dat... (20 Replies)
Discussion started by: Akshay Hegde
20 Replies

7. Shell Programming and Scripting

How to find empty files in a directory and write their file names in a text?

I need to find empty files in a directory and write them into a text file. Directory will contain old files as well, i need to get the empty files for the last one hour only. (1 Reply)
Discussion started by: vel4ever
1 Replies

8. Shell Programming and Scripting

Grepping file names, comparing them to a directory of files, and moving them into a new directory

got it figured out :) (1 Reply)
Discussion started by: sHockz
1 Replies

9. Shell Programming and Scripting

Searching for file names in a directory while ignoring certain file names

Sun Solaris Unix Question Haven't been able to find any solution for this situation. Let's just say the file names listed below exist in a directory. I want the find command to find all files in this directory but at the same time I want to eliminate certain file names or files with certain... (2 Replies)
Discussion started by: 2reperry
2 Replies

10. Shell Programming and Scripting

How to have a Script that extracts files?

Hi, I know there is a way to have a script that include files in a way that once we run the script, it would extract those files. Kinda similar to how zip files work. For example: - I have a script called test.sh - Once I run this script, it will extract file1, file2 and file3 and then... (2 Replies)
Discussion started by: pgarousi
2 Replies
Login or Register to Ask a Question