Request for file read option in Unix shell scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Request for file read option in Unix shell scripting
# 1  
Old 06-01-2011
Request for file read option in Unix shell scripting

Hi Friends,

I would like to read all the record from one txt file to other file txt

For example I have two txt file a.txt and b.txt. I need to read a.txt record by record and I need add the system date @ end of each record before moving it to b.txt. Could you please share the coding for this, I am very much new to this language. Thanks in advance.

For Example:
a.txt file contains the below record
Sample text record 1
Sample text record 2
Sample text record 3
Sample text record 4
Sample text record 5
Sample text record 6

After running my script it should generate b.txt as below
Sample 06/01/2011 text record 1
Sample 06/01/2011 text record 2
Sample 06/01/2011 text record 3
Sample 06/01/2011 text record 4
Sample 06/01/2011 text record 5
Sample 06/01/2011 text record 6

Regards,
Vinoth R
# 2  
Old 06-01-2011
Try this:
Code:
awk '{$1=$1" 06/01/2011"}1' a.txt > b.txt

# 3  
Old 06-01-2011
Code:
DATE=`date +%m/%d/%Y`
while read A B
do
        echo $A $DATE $B
done < a.txt > b.txt

# 4  
Old 06-01-2011
This one will do the job as well (assuming all the lines start with "Sample "):

Code:
sed "s|^Sample \(.*\)|Sample $(date +%m/%d/%Y) \1|g" a.txt > b.txt

# 5  
Old 06-01-2011
Quote:
Originally Posted by ciupinet
This one will do the job as well (assuming all the lines start with "Sample "):

Code:
sed "s|^Sample \(.*\)|Sample $(date +%m/%d/%Y) \1|g" a.txt > b.txt

You don't even need a back reference here :

Code:
sed "s|^Sample |&$(date +%m/%d/%Y) |" a.txt >b.txt

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. Shell Programming and Scripting

UNIX Shell Scripting (Solaris) for File Checking

Hi guys, I'm sorry but i badly need your help. I am assigned to do a basic shell script in my job but sadly i don't have any idea on what it is because i am an electronics engineer, but i googled all of it, ask my friends but i cant finalize my scripts. so do please help me. The requirement... (47 Replies)
Discussion started by: daveaztig14
47 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

sh file: READ (menu) but now run with option

I have a script which uses READ to detect choice of menu option...now I want to change the script without doing whole rewrite such that when user runs ./script.sh 5 it would execute menu option 5 rather than user running ./script.sh waiting for it to load and then pressing "5 enter" Is it... (1 Reply)
Discussion started by: holyearth
1 Replies

5. Shell Programming and Scripting

generate tabular output from an input text file in unix shell scripting

Hi, I have the output (as below) which i want it to be in a table. For e.g. space utilization in PSE on path /logs is 0% space utilization in PSE on path /logs/tuxedo/tuxlsp is 16% space utilization in PSE on path /ldvarlsp/lsp/log is 37% space utilization in PSE on path /home is 6%... (7 Replies)
Discussion started by: pkbond
7 Replies

6. Shell Programming and Scripting

read -p "prompt text" foo say "read: bad option(s)" in Bourne-Shell

Hallo, i need a Prompting read in my script: read -p "Enter your command: " command But i always get this Error: -p: is not an identifier When I run these in c-shell i get this error /usr/bin/read: read: bad option(s) How can I use a Prompt in the read command? (9 Replies)
Discussion started by: wiseguy
9 Replies

7. UNIX for Dummies Questions & Answers

Unix Shell Scripting -- update employees not present in input file

ALL, My shell script takes a employee file as input. I have to identify the list of employees not in the input file and update their status in the database. Approach I followed: by traversing through the input file add all the emplid's to a variable. update the status of employees not in... (2 Replies)
Discussion started by: sailussr
2 Replies

8. AIX

Unix shell scripting to find latest file having timestamp embedded...

Hi guys, I have a directory in UNIX having files with the below format, i need to pickup the latest file having recent timestamp embedded on it, then need to rename it to a standard file name. Below is the file format: filename_yyyymmdd.csv, i need to pick the latest and move it with the... (2 Replies)
Discussion started by: kaushik25
2 Replies

9. Shell Programming and Scripting

why shell scripting takes more time to read a file

i have done a coding in shell scripting which reads a file line by line and does something....it takes more than 30 seconds to execute for a single file. when i do the same with perl scripting it takes less than a second. is that shell scripting is not efficient while working with large number of... (1 Reply)
Discussion started by: brkavi_in
1 Replies

10. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies
Login or Register to Ask a Question