Read multiple text file in shell sccript


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read multiple text file in shell sccript
# 1  
Old 07-05-2012
Read multiple text file in shell sccript

I need help. I need to read all current and incoming text file in the directory and change it's content to 0.

The following code change the content of the text file to 0, however, the code always assumes that the files are ALREADY present. Is there any way where I can change the file1_.txt, file_2.txt, file_3.txt with only .txt extension and still change the content of the .txt file
Code:
#!/bin/sh 

for file in file_1.txt file_2.txt file_3.txt
do
    awk '{ print "0" }' $file > tmp.tmp
    mv tmp.tmp $file
done

Thanks for the help!

Last edited by Franklin52; 07-05-2012 at 08:28 AM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 07-05-2012
try this.....

Code:
for file in file_1.txt file_2.txt file_3.txt
do
    echo "0" > $file 
done

# 3  
Old 07-05-2012
try this..

Code:
 
for i in *.txt
do
     echo "0" > $i
done

# 4  
Old 07-05-2012
Quote:
Originally Posted by itkamaraj
try this..

Code:
 
for i in *.txt
do
     echo "0" > $i
done


Thanks a lot. It works! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies

2. UNIX for Beginners Questions & Answers

Shell - Read a text file with two words and extract data

hi I made this simple script to extract data and pretty much is a list and would like to extract data of two words separated by commas and I would like to make a new text file that would list these extracted data into a list and each in a new line. Example that worked for me with text file... (5 Replies)
Discussion started by: dandaryll
5 Replies

3. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

4. Shell Programming and Scripting

How to create a shell script to read a foldername from a text file and go to the folder?

Hi, I am trying to write a shell script which can read folder names from a text file and then go to the folder and picks up a xml file and write on my sipp script so that I can run the sipp script. For example: I have a text file called thelist.txt where I have provided all the folders... (7 Replies)
Discussion started by: pm1504
7 Replies

5. Shell Programming and Scripting

How to read the data from the text file in shell script?

I am having one text file and i need to read that data from my shell script. I will expain you the scenario: Script look like: For name type 1: For age type 2: For Salary type3: echo "Enter the input:" read the data if input is 1 then go to the Text file and print the... (2 Replies)
Discussion started by: dineshmurs
2 Replies

6. Shell Programming and Scripting

Shell script to read lines in a text file and filter user data

hi all, I have this file with some user data. example: $cat myfile.txt FName|LName|Gender|Company|Branch|Bday|Salary|Age aaaa|bbbb|male|cccc|dddd|19900814|15000|20| eeee|asdg|male|gggg|ksgu|19911216||| aara|bdbm|male|kkkk|acke|19931018||23| asad|kfjg|male|kkkc|gkgg|19921213|14000|24|... (4 Replies)
Discussion started by: srimal
4 Replies

7. Shell Programming and Scripting

shell script to read data from text file and to load it into a table in TOAD

Hi....can you guys help me out in this script?? Below is a portion text file and it contains these: GEF001 000093625 MKL002510 000001 000000 000000 000000 000000 000000 000001 GEF001 000093625 MKL003604 000001 000000 000000 000000 000000 000000 000001 GEF001 000093625 MKL005675 000001... (1 Reply)
Discussion started by: pallavishetty
1 Replies

8. Shell Programming and Scripting

how can i read text file and assign its values to variables using shell

Hello, I have a cat.dat file, i would like shell to read each 3 lines and set this 3 lines to 3 different variables. my cat.dat is: 11 12 +380486461001 12 13 +380486461002 13 14 +380486461003 i want shell to make a loop and assign 1st line to student_id, 2nd line to... (4 Replies)
Discussion started by: rosalinda
4 Replies

9. Shell Programming and Scripting

read list of filenames from text file and remove these files in multiple directories

I have a large list of filenames from an Excel sheet, which I then translate into a simple text file. I'd like to use this list, which contains various file extensions , to archive these files and then remove them recursively through multiple directories and subdirectories. So far, it looks like... (5 Replies)
Discussion started by: fxvisions
5 Replies

10. UNIX for Dummies Questions & Answers

To Read a text file using shell Programming

Hello! I need to read a text file containing certains rows and columns!The following is a sample file with only three rows! 01:41:30:00:05:51 OFF 48506649K 5769415 63494357K 01:41:30:00:05:65 ON 4493546K 27266552 5880264K 01:41:30:00:05:78 OFF 614556K 89121 47291K... (1 Reply)
Discussion started by: sandytul
1 Replies
Login or Register to Ask a Question