printing the content from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting printing the content from a file
# 1  
Old 06-30-2009
printing the content from a file

hi ,
i m new to unix and i don no how to print this format
i have output file like

THE DOMAIN NAME VPORCL01 FOR THE HOSTNAME Ram-pc
Port=1533
Port=9000
Listener Port=9100


THE DOMAIN NAME VPORCL02 FOR THE HOSTNAME Ram-pc
Port=7000
Port=9000
Listener Port=9100

but i sholud print output this format

instance name WSL port JSL port JRAD port

VPORCL01 1533 9000 9100

VPORCL02 7000 9000 9100

can any one help ...thanks in advance


with regards,


ram
# 2  
Old 06-30-2009
Try this...

cat <input-file> | egrep "VPORCL|Port" | sed 's/THE DOMAIN NAME //g' | paste - - - -

---------- Post updated at 08:01 PM ---------- Previous update was at 07:52 PM ----------

This would be more clear

cat <input-file> | egrep "VPORCL|Port" | sed 's/THE DOMAIN NAME //g;s/Port=//g;s/Listener//g;s/FOR THE HOSTNAME Ram-pc//g' | paste - - - -

Last edited by jayan_jay; 06-30-2009 at 11:41 AM..
# 3  
Old 06-30-2009
Hammer & Screwdriver

This shall be clear, input file is temp_file

Code:
 
X=0
Y=0
cat -n temp_file | grep VPORCL | awk '{print $1}' > temp_head
while read line
do
arr_head[$X]=$line
X=`expr $X + 1`
done < temp_head
cat -n temp_file | grep "Listener Port" | awk '{print $1}' > temp_tail
while read line
do
arr_tail[$Y]=$line
Y=`expr $Y + 1`
done < temp_tail
n=0
while [ $n -lt $Y ]
do
var1=`echo ${arr_head[$n]}`
var2=`echo ${arr_tail[$n]}`
sed -n "${var1},${var2}p" temp_file > tmp_part_file
instance=`cat tmp_part_file | sed -n "1p" | awk '{print $4}'`
WSL=`cat tmp_part_file | sed -n "2p"  | awk -F"=" '{print $2}'`
JSL=`cat tmp_part_file | sed -n "3p"  | awk -F"=" '{print $2}'`
JRAD=`cat tmp_part_file | sed -n "4p"  | awk -F"=" '{print $2}'`
echo $instance $WSL $JSL $JRAD
n=`expr $n + 1`
done


Last edited by jim mcnamara; 06-30-2009 at 11:59 AM.. Reason: add code tags
# 4  
Old 06-30-2009
hi
thanxs for ur reply..... i have formatted the output now the file looks like this
VPORCL01
Ram-pc
1533
9000
9100


VPORCL02
Ram-pc
7000
9000
9100
now ,
i need to print this out put in this format

VPORCL01 Ram-pc 1533 9000 9100
VPORCL02 Ram-pc 7000 9000 9100
# 5  
Old 06-30-2009
Power

X=0
Y=0
cat -n temp_file | grep VPORCL | awk '{print $1}' > temp_head
while read line
do
arr_head[$X]=$line
arr_tail[$Y]=`expr ${arr_head[$X]} + 4`
X=`expr $X + 1`
Y=`expr $Y + 1`
done < temp_head
n=0
while [ $n -lt $Y ]
do
var1=`echo ${arr_head[$n]}`
var2=`echo ${arr_tail[$n]}`
sed -n "${var1},${var2}p" temp_file > tmp_part_file
instance=`cat tmp_part_file | sed -n "1p"`
Ram=`cat tmp_part_file | sed -n "1p"`
WSL=`cat tmp_part_file | sed -n "2p"`
JSL=`cat tmp_part_file | sed -n "3p"`
JRAD=`cat tmp_part_file | sed -n "4p"`
echo $instance $Ram $WSL $JSL $JRAD
n=`expr $n + 1`
done
# 6  
Old 06-30-2009
awk:
Code:
echo 'instance name WSL port JSL port JRAD port'; echo ""
awk '/^THE/ {printf("%s\t", $4); next}
     /=/ { gsub( /.*=/, "", $0); printf("%s\t", $0); next}
     /^$/ {printf("\n")}
    ' filename

output:
Code:
/home/jmcnama> t.awk
instance name WSL port JSL port JRAD port

VPORCL01        1533    9000    9100

VPORCL02        7000    9000    9100

# 7  
Old 06-30-2009
thanks for all , its working fine Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert content of a file to another file at a line number which is given by third file

Hi friends, here is my problem. I have three files like this.. cat file1.txt ======= unix is best unix is best linux is best unix is best linux is best linux is best unix is best unix is best cat file2.txt ======== Windows performs better Mac OS performs better Windows... (4 Replies)
Discussion started by: Jagadeesh Kumar
4 Replies

2. Shell Programming and Scripting

How to remove exisiting file content from a file and have to append new file content?

hi all, i had the below script x=`cat input.txt |wc -1` awk 'NR>1 && NR<'$x' ' input.txt > output.txt by using above script i am able to remove the head and tail part from the input file and able to append the output to the output.txt but if i run it for second time the output is... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

3. Shell Programming and Scripting

Change the file name and copy old file content to new file names.

Hi, I have a files in a directory as below :- ls -1 mqdepth-S1STC02 proc-mq-S1STC01 proc-mq-S1STC02 proc-mq-S1STC03 Whereever i have S1STC i need to copy them into new file with file name S2STC. expected output :- ls -1 mqdepth-S2STC02 proc-mq-S2STC01 proc-mq-S2STC02... (3 Replies)
Discussion started by: satishmallidi
3 Replies

4. Shell Programming and Scripting

Facing issues with Content-Type:application/x-download Content-Disposition:attachment

I am in the process of developing a perl cgi page. I had succeeded in developing the page but there are few errors/issues with the page. description about cgi page: My CGI page retrieves all the file names from an directory and displays the files in drop down menu for downloading the... (5 Replies)
Discussion started by: scriptscript
5 Replies

5. Shell Programming and Scripting

Sed: replace content from file with the content from file

Hi, I am having trouble while using 'sed' with reading files. Please help. I have 3 files. File A, file B and file C. I want to find content of file B in file A and replace it by content in file C. Thanks a lot!! Here is a sample of my question. e.g. (file A: a.txt; file B: b.txt; file... (3 Replies)
Discussion started by: dirkaulo
3 Replies

6. UNIX for Dummies Questions & Answers

Sco Unix printing : jobs hangs in queue - printing via lp versus hpnpf

Hi, We have a Unix 3.2v5.0.5. I installed a printer via scoadmin, HP network printer manager with network peripheral name (hostname and ipadres are in /etc/hosts). This is the configuration file : Code: root@sco1 # cat configurationBanner: on:AlwaysContent types: simpleDevice:... (0 Replies)
Discussion started by: haezeban
0 Replies

7. Windows & DOS: Issues & Discussions

Linux to Windows Printing: PDF starts printing from middle of page.

We are using Red Hat. We have a issue like this: We want to print from Linux, to a printer attached to a Windows machine. What we want to print is a PDF. It prints, but the printing starts from the middle of the page. In the report, there is no space at the top but still printing starts from the... (5 Replies)
Discussion started by: rohan69
5 Replies

8. Shell Programming and Scripting

Printing out desired content

I want this script to read notes and print the contents of any file that starts with messages and is possibly followed by a period and a digit. I've made this code, but how do I make it so that IF there is a period and a digit. Right now it only prints out the result if it is for example;... (8 Replies)
Discussion started by: HardyV2
8 Replies

9. Shell Programming and Scripting

Need help with awk - how to read a content of a file from every file from file list

Hi Experts. I need to list the file and the filename comes from the file ListOfFile.txt. Basicly I have a filename "ListOfFile.txt" and it contain Example of ListOfFile.txt /home/Dave/Program/Tran1.P /home/Dave/Program/Tran2.P /home/Dave/Program/Tran3.P /home/Dave/Program/Tran4.P... (7 Replies)
Discussion started by: tanit
7 Replies
Login or Register to Ask a Question