Assistance Required - manipulating records


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Assistance Required - manipulating records
# 1  
Old 10-25-2011
Assistance Required - manipulating records

Hi guys, I need to do a bit of work to a file.

Basically I want to run a SQL statement against each record in this file (hundreds of lines):

sample input:
Code:
233333
233334
233335
233336

I want to do the following:

1. Add a some text at the beginning to prepare the SQL (3 lines)
2. Add some text at the end for cleanup (4 lines)
3. Remove whitespace at the end - SORTED sed 's/[ \t]*$//' - seems to leave 2 spaces?!!??!)
4. Add a letter 'a'to the end - SORTED (awk 'print $0 "a"})
5. Now the complicated part, I want to take the number above and make it look like the sample output below. The same for each line.....!?

Code:
COPY BATCH_233333a INTO /dir/dir/dir/BATCH_233333a.txt
COPY BATCH_233334a INTO /dir/dir/dir/BATCH_233334a.txt
COPY BATCH_233335a INTO /dir/dir/dir/BATCH_233335a.txt
COPY BATCH_233336a INTO /dir/dir/dir/BATCH_233336a.txt

Any help is appreciated
# 2  
Old 10-25-2011
Code:
sed 's#.*#COPY BATCH_&a /dir/dir/dir/BATCH_&a.txt#' myFile

# 3  
Old 10-25-2011
its official i love you

Thanks, anyn thoughts as to why the following awk doesn't add the "a" directly to the end of the line but instead adds it like:

input
Code:
9315
9602
9604
9734
9746
9750
9753

Code:
9315  a
9602  a
9604  a
9734  a
9746  a
9750  a
9753  a

awk 'print $0 "a"}
# 4  
Old 10-25-2011
Probably you have spaces in your input file!
Try:
Code:
sed 's# ##g' <inFile>

Or better:
Code:
sed 's#[ \t]##g' <inFile>

This User Gave Thanks to felipe.vinturin For This Post:
# 5  
Old 10-25-2011
Quote:
Originally Posted by mcclunyboy
its official i love you

Thanks, anyn thoughts as to why the following awk doesn't add the "a" directly to the end of the line but instead adds it like:

input
Code:
9315
9602
9604
9734
9746
9750
9753

Code:
9315  a
9602  a
9604  a
9734  a
9746  a
9750  a
9753  a

awk 'print $0 "a"}
probably 'cause it's syntactically incorrect statement...
Code:
awk '{print $0 "a"}' myFile

This User Gave Thanks to vgersh99 For This Post:
# 6  
Old 10-25-2011
edit - please wait - I am producing a new input file.

syntax was ok in awk - typo here on this site
# 7  
Old 10-25-2011
Code:
awk '{printf "COPY BATCH_%sa INTO /dir/dir/dir/BATCH_%sa.txt\n", $1,$1}' infile

This User Gave Thanks to rdcwayx For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Assistance required to decode sed search using /1

Hi, I am trying to extract line number (first number), as well as everything from TSVal onwards. 4 1.474005 172.18.124.142 -> 74.125.228.46 TCP 2450940617 74 44021 > https Seq=0 Win=5840 Len=0 MSS=1380 SACK_PERM=1 TSval=2450940617 TSecr=0 WS=64 6 1.488149 172.18.124.142 ->... (1 Reply)
Discussion started by: sand1234
1 Replies

2. Shell Programming and Scripting

Manipulating Data Records for reporting

Hello All, I have Data Records (DRs) with the following format: ... (2 Replies)
Discussion started by: EAGL€
2 Replies

3. Shell Programming and Scripting

UNIX Script required for count the records in table

Hi Friends, I looking for the script for the count of the records in table. and then it's containg the zero records then should get abort. and should notify us through mail. Can you please help me out in this area i am lacking. (5 Replies)
Discussion started by: victory
5 Replies

4. Shell Programming and Scripting

Assistance required with awk and regular expressions

Hello there, I am trying to get my head around the section below of a script we use that incorporates AWK and Regular Expressions. { match($0,"The broker*");print $1,$2,$3 ":", substr($0, RSTART,RLENGTH)} I have a basic understanding of how match works, what I am struggling with is the... (2 Replies)
Discussion started by: jimbojames
2 Replies

5. Shell Programming and Scripting

Compare two files with different number of records and output only the Extra records from file1

Hi Freinds , I have 2 files . File 1 |nag|HYd|1|Che |esw|Gun|2|hyd |pra|bhe|3|hyd |omu|hei|4|bnsj |uer|oeri|5|uery File 2 |nag|HYd|1|Che |esw|Gun|2|hyd |uer|oi|3|uery output : (9 Replies)
Discussion started by: i150371485
9 Replies

6. Hardware

Assistance required when booting M3000, error shows; * MBU_A Status:Degraded; Ver:0701h; Serial:

Here is the error showing in the XCSF, can anyone recommend further diagnosis for this specific error?; XSCF> showhardconf SPARC Enterprise M3000; + Serial:PX61142029; Operator_Panel_Switch:Locked; + Power_Supply_System:Single; SCF-ID:XSCF#0; + System_Power:On;... (4 Replies)
Discussion started by: Touchpoint
4 Replies

7. UNIX for Dummies Questions & Answers

Grep specific records from a file of records that are separated by an empty line

Hi everyone. I am a newbie to Linux stuff. I have this kind of problem which couldn't solve alone. I have a text file with records separated by empty lines like this: ID: 20 Name: X Age: 19 ID: 21 Name: Z ID: 22 Email: xxx@yahoo.com Name: Y Age: 19 I want to grep records that... (4 Replies)
Discussion started by: Atrisa
4 Replies

8. Shell Programming and Scripting

Getting required fields from a test file in required fromat in unix

My data is something like shown below. date1 date2 aaa bbbb ccccc date3 date4 dddd eeeeeee ffffffffff ggggg hh I want the output like this date1date2 aaa eeeeee I serached in the forum but didn't find the exact matching solution. Please help. (7 Replies)
Discussion started by: rdhanek
7 Replies

9. Shell Programming and Scripting

Based on num of records in file1 need to check records in file2 to set some condns

Hi All, I have two files say file1 and file2. I want to check the number of records in file1 and if its atleast 2 (i.e., 2 or greater than 2 ) then I have to check records in file2 .If records in file2 is atleast 1 (i.e. if its not empty ) i have to set some conditions . Could you pls... (3 Replies)
Discussion started by: mavesum
3 Replies

10. Shell Programming and Scripting

awk script required for finding records in 1 file with corresponding another file.

Hi, I have a .txt file (uniqfields.txt) with 3 fields separated by " | " (pipe symbol). This file contains unique values with respect to all these 3 fields taken together. There are about 40,000 SORTED records (rows) in this file. Sample records are given below. 1TVAO|OVEPT|VO... (2 Replies)
Discussion started by: RRVARMA
2 Replies
Login or Register to Ask a Question