Desire structure for input file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Desire structure for input file
# 1  
Old 09-19-2010
Desire structure for input file

Hello Unix gurus,

I have a txt file with single columns with n no of rows.like below

COLUMN1
=======


AAA
BBB
CCC
DDD
EEE
FFF
GGG
HHH
.
.
.
NNN.

i need to iterate the above input for row count (row count is not fixed).The out put structure should be like below in between special characters

are required to add to oupt put like (<> ,A. ,B.) .

o/p
----

A.AAA <> B.AAA or
A.BBB <> B.BBB or
A.CCC <> B.CCC or
A.DDD <> B.DDD or
A.EEE <> B.EEE or
.
.
.
A.NNN <> B.NNN;

Can any body suggest how to write this using scripting.

Last edited by kanakaraju; 09-19-2010 at 04:30 PM..
kanakaraju
# 2  
Old 09-19-2010
Code:
sed 's/.*/A.& <> B.& or/; $s/ or$/;/'

Example:
Code:
$ cat data
AAA
BBB
CCC
DDD
EEE
FFF
GGG
HHH
$ sed 's/.*/A.& <> B.& or/; $s/ or$/;/' data
A.AAA <> B.AAA or
A.BBB <> B.BBB or
A.CCC <> B.CCC or
A.DDD <> B.DDD or
A.EEE <> B.EEE or
A.FFF <> B.FFF or
A.GGG <> B.GGG or
A.HHH <> B.HHH;

Regards,
Alister
# 3  
Old 09-19-2010
Code:
awk '{print "A." $1 " <> B." $1 " or "}' infile

# 4  
Old 09-19-2010
Code:
$ ruby -ne 'BEGIN{s=""};print s if s;s=gsub(/^(.*)$/,"A.\\1 <> B.\\1 or");END{puts s.strip.gsub("or","")+";"}' file
A.AAA <> B.AAA or
A.BBB <> B.BBB or
A.CCC <> B.CCC or
A.DDD <> B.DDD or
A.EEE <> B.EEE or
A.FFF <> B.FFF or
A.GGG <> B.GGG or
A.HHH <> B.HHH ;

# 5  
Old 09-20-2010
Desire structure for input file

Hello Alister,

Thanks for your inputs.I have executed the command which u suggested.

======================
more test.txt
AAA
BBB
CCC
DDD
EEE
FFF
======================

"test.txt" 7L, 25C written
sl000247:/db2mig/data/back_out $ sed 's/.*/A.& <> B.& or/; $s/ or$/;/' test.txt
A.AAA <> B.AAA or
A.BBB <> B.BBB or
A.CCC <> B.CCC or
A.DDD <> B.DDD or
A.EEE <> B.EEE or
A.FFF <> B.FFF or
A. <> B.;

observe the last 2 lines i have the last line in my input file is FFF

so in the ouput we should get like ..


A.AAA <> B.AAA or
A.BBB <> B.BBB or
A.CCC <> B.CCC or
A.DDD <> B.DDD or
A.EEE <> B.EEE or
A.FFF <> B.FFF ;


---------- Post updated at 02:38 AM ---------- Previous update was at 02:33 AM ----------

Hello kurumi,

i could not able to find out ruby on bash.

ruby -ne 'BEGIN{s=""};print s if s;s=gsub(/^(.*)$/,"A.\\1 <> B.\\1 or");END{puts s.strip.gsub("or","")+";"}' test.txt
-bash: ruby: command not found



kanakaraju
# 6  
Old 09-20-2010
Take a look at your data file with `od` or `hexdump` or `vis` or `sed -n l` or `cat -vet` and you'll probably find some character that doesn't show up on your terminal; that's almost certainly the source of the extra line at the end of my sed suggestion's output. Perhaps it's a stray carriage return or other control character?

Also, your sample output in your most recent post differs from that of your original post. The latter has a space before the final semi-colon; the former does not. If you want that space, use this slightly modified version of my original suggestion:
Code:
sed 's/.*/A.& <> B.& or/; $s/or$/;/'

Regards,
Alister
# 7  
Old 09-20-2010
Desire structure for input file

Hello Alister,

Thanks the latest post work for me .

Appriciate your help.

Regards
kanaka

---------- Post updated at 05:43 AM ---------- Previous update was at 02:52 AM ----------

Hello Alister,

I started using our sed in my script.

i have file report3.txt with content

more report3.txt

--------------------
AAAA
BBBB
CCCC
..
..
XXXX
YYYY
ZZZZ

26 record(s) selected.

when i use our sed command now the results is displazing 2 more lines in the begining and 1 more line extra in the bottom.

A. <> B. or
A. <> B. or
A.-------------------- <> B.-------------------- or
A.AAA <> B.AAA or
..
..
A.ZZZ <> B.ZZZ or
A. <> B. or
A. 26 record(s) selected. <> B. 26 record(s) selected. or
A. <> B. ;

I don't want the lines in red colour should be display in my output .any suggessions how to discard those line while printing?
kanakaraju
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to get desire line?

Hi Guys, I am newbie here and greeting to all guys of unix forum, now I want to learn unix here. I have query here, we have file where file has 20 line record, now i want display 10 to 15 line row record only, then how it possible. (5 Replies)
Discussion started by: aaditya321
5 Replies

2. Shell Programming and Scripting

Read input files and merge them in given order and write them to input one param or one file

Dear Friends, I am looking for a shell script to merge input files into one file .. here is my idea: 1st paramter would be outfile file (all input files content) read all input files and merge them to input param 1 ex: if I pass 6 file names to the script then 1st file name as output file... (4 Replies)
Discussion started by: hyd1234
4 Replies

3. Shell Programming and Scripting

Case structure combined with standard input

Hi folks, I am new to bash scripting so please excuse my question. Is there any chance to combine a case structure with the read command? Like case (read -p "" variable) in x) Thx! (7 Replies)
Discussion started by: haukee
7 Replies

4. Hardware

HTC Desire S vs HTC Desire C - USB Android tethering problem

Hi gurus, I have problem with android usb tethering (usb0 interface). I tried two phones HTC Desire C and HTC Desire S. With Desire C everything works as expected, usb0 automatically goes up and gains IP address and tethering is working (output bellow) HTC Desire C: Nov 6 23:32:36 HP-PC... (0 Replies)
Discussion started by: wakatana
0 Replies

5. Shell Programming and Scripting

Copy files from input file with dir structure

hi, I want to copy files from source directory based on input file (or output of previous command) and i want to have the SAME DIRECTORY STRUCTURE. Note that i will have other files and directories which i dont want to copy to destination. For example, dir source has following content:... (22 Replies)
Discussion started by: dragon.1431
22 Replies

6. Shell Programming and Scripting

Need script to take input from file, match on it in file 2 and input data

All, I am trying to figure out a script to run in windows that will allow me to match on First column in file1 to 8th Column in File2 then Insert file1 column2 to file2 column4 then create a new file. File1: 12345 Sam 12346 Bob 12347 Bill File2:... (1 Reply)
Discussion started by: darkoth
1 Replies

7. Shell Programming and Scripting

Can't get DF output I desire

I currently have a shell script that creates Oracle databases configured the way we want them here. One part of it allows you to choose which file system to place the database files. This is the command which works. This produces a list of file systems from which to choose. I have been... (1 Reply)
Discussion started by: sewood
1 Replies

8. Shell Programming and Scripting

How to create a directory structure with getting input from a file.

Hi How to create a directory structure with getting input from a file. I have file in that following lines are written. ./activemq-4.1.2/activemq-core-4.1.2.jar ./activemq-4.1.2/backport-util-concurrent-2.1.jar ./camel-1.4.0/apache-camel-1.4.0.jar ./camel-1.4.0/lib/activation-1.1.jar... (12 Replies)
Discussion started by: itsjoy2u
12 Replies

9. Programming

Search attributes in one structure using the values from another structure

Hello Groups I am trying to find out ways of comparing a value from a 'c' structure to a value in another 'C' structure. the 'C' structure can be a List or liked list as it contains lot many records. if we loop it in both the structures it is going to consume time. I am looking for a simple... (3 Replies)
Discussion started by: dhanamurthy
3 Replies

10. UNIX for Dummies Questions & Answers

Copying a Directory Structure to a new structure

Hi all Is it possible to copy a structure of a directory only. e.g. I have a file with the following entries that is a result of a find :- /dir1/dir2/file.dbf /dir1/dir2/dir3/file1.dbf /dir1/file.dbf I want to copy these to a directory and keep the structure however starting at a new dir... (8 Replies)
Discussion started by: jhansrod
8 Replies
Login or Register to Ask a Question