Reading txt files using the awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading txt files using the awk
# 1  
Old 08-16-2012
Reading txt files using the awk

Dear Shell scripters,

I have a small code which copy the txt files from some destination to file name OutPutFile. [1]
I want to modify this script to introduce several constant.

The string it is reading is like
Code:
/eos/uscms/store/user/pooja04//analysis2012/525/data/doubleele/2012/datav1/vgtree_320_1_YiM.root

I want the final string in the OUTPUTFILE to be like:
Code:
Chain->Add("/eos/uscms/store/user/pooja04//analysis2012/525/data/doubleele/2012/datav1/vgtree_320_1_YiM.root");

I don't know how to add these constant like [", ;] etc. Kindly help.

Thanks in advance
Pooja


SCRIPT [1]
=========================
Code:
#!/bin/bash                                                                                                                                                            
#usage ./copyTextFromCastor.sh $PATH $GREP $OUTPUTFILE                                                                                                                 

PATHNAME=$1
CONSTANT=Chain
GREP=$2
OUTPUT=$3
echo "Copying \"$1 | grep $2\" to $3"

ls -ltr "$PATHNAME" | grep "$2" | awk '{print string path $9}' string="$CONSTANT" path="$1"  > "$3"
echo "progressing ... please be patient..."


Last edited by nrjrasaxena; 08-16-2012 at 03:46 AM..
# 2  
Old 08-16-2012
If you don't mind using sed, try
Code:
sed 's/^/Chain->Add("/; s/$/");/'

as a filter in your long pipe. It just replaces the start-of-string (^) with your first constant and the end-of-string ($) with the second.
If this does not do what you want, pls post more info on your problem, as I'm not sure I understand what your script is doing.
# 3  
Old 08-16-2012
use in your script if that code is printing the output to your file
Code:
awk '{print string"->Add(\"" path $9"\");"}' string="$CONSTANT"  path="$1"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk, sed, shell all words in INPUT.txt find in column1 of TABLE.txt and replce with column2 in

Hi dears i have text file like this: INPUT.txt 001_1_173 j nuh ]az 001_1_174 j ]esma. nuh ]/.xori . . . and have another text like this TABLE.txt j j nuh word1... (6 Replies)
Discussion started by: alii
6 Replies

2. Shell Programming and Scripting

Desired output.txt for reading txt file using awk?

Dear all, I have a huge txt file (DATA.txt) with the following content . From this txt file, I want the following output using some shell script. Any help is greatly appreciated. Greetings, emily DATA.txt (snippet of the huge text file) 407202849... (2 Replies)
Discussion started by: emily
2 Replies

3. UNIX for Dummies Questions & Answers

Comparing two txt files with AWK

Hi, I need to compare two text files with awk. File1: ------- chr1 43815007 43815009 COSM19193 REF=TG;OBS=AA;ANCHOR=G AMPL495041 chr1 43815008 43815009 COSM18918 REF=G;OBS=T;ANCHOR=T AMPL495041 chr1 115256527 115256528 ... (6 Replies)
Discussion started by: RushiK
6 Replies

4. Shell Programming and Scripting

Help with reading two input files in awk

Hello, I'm trying to write an awk program that reads two files inputs. example, file 1: 0.00017835 0.000176738 0.00018811 0.000189504 0.000188155 0.000180065 0.000178991 0.000178252 0.000182513 file 2: 1.7871769E-05 1.5139576E-16 1.5140196E-16 1.5139874E-16 1.7827407E-04 ... (5 Replies)
Discussion started by: joseamck
5 Replies

5. Shell Programming and Scripting

awk append fileA.txt to growing file B.txt

This is appending a column. My question is fairly simple. I have a program generating data in a form like so: 1 20 2 22 3 23 4 12 5 43 For ever iteration I'm generating this data. I have the basic idea with cut -f 2 fileA.txt | paste -d >> FileB.txt ???? I want FileB.txt to grow, and... (4 Replies)
Discussion started by: theawknewbie
4 Replies

6. Shell Programming and Scripting

reading files using awk

Hi , I have a awk script to read a file using getline, but when its not able to recognize the path of the file. I am working on solaris unix. nawk -F'|' ' BEGIN{ FILE1="/input_files/temp.txt" } I have to place my script in the same folder i.e /input_files/ for my script to work. ... (2 Replies)
Discussion started by: rashmisb
2 Replies

7. Shell Programming and Scripting

awk-files in a txt

There is a file that contains access's data to a web server. Each line of the file (it's big) it's : IP Client - - "Command Path Protocol" code size "client software" Example,for the first line: IP Client is 67.195.37.107, date-hour is , Command Path Protocol is "Get /papers/ISO4nm.pdf ... (1 Reply)
Discussion started by: Mark_orig
1 Replies

8. Shell Programming and Scripting

Reading files using AWK or SED

hi Friends, Please help me to give a try for writing a shell script either with awk or SED for the below requirement. i have file with 3 lines, each of size 3200 chars, wanted to read this file and divide eachline with 200 columns with differensizes for each column value by keeping seperator.... (3 Replies)
Discussion started by: balireddy_77
3 Replies

9. Shell Programming and Scripting

reading from 2 files using awk

hi, Is it possible to read and compare 2 files which have different Field separators at the same time using awk??? file1: 1,dayal,maruti,Z-234,bangalore,KA,........ 2,yash,esteem,Y-007,delhi,DL,........... . . . fill 2: Z-234|Registered|Bangalore Y-007|Registered|Bangalore . . . ... (2 Replies)
Discussion started by: VGR
2 Replies

10. Shell Programming and Scripting

Reading Two files at the same time using awk

Hi All, I am very new to awk script writing. I have two files(file1 and file2) containing some numbers. I want divide the numbers in file1 with those in file 2 line wise. is it possible to simultaneousely read the information from both files and carry put the division. Thanks a lot in... (6 Replies)
Discussion started by: suneeldutt
6 Replies
Login or Register to Ask a Question