I want some selected data from first file and put into other file in specified format


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers I want some selected data from first file and put into other file in specified format
# 1  
Old 04-24-2009
Question I want some selected data from first file and put into other file in specified format

I have a file with follwing content
----------------------------------
SCHEDULE XXXXXXXXX#JOBCOUNT
ON EVERYDAY
AT 0000
PRIORITY 50
SCHEDULE XXXXXXXXX#ABCDEFGH
ON EVERYDAY
AT 0001
PRIORITY 29
SCHEDULE XXXXXXXXX#ABCD1234
ON EVERYDAY
AT 0002
PRIORITY 40
SCHEDULE XXXXXXXXX#12345678
ON EVERYDAY
AT 0003
PRIORITY 56
----------------------------------
Now, I want to generate output like below

JOBCOUNT| EVERYDAY |0000|50
ABCDEFGH| EVERYDAY |0001|29
ABCD1234| EVERYDAY |0002|40
12345678|EVERYDAY |0003|56

and put this output in other file.

Can someone help me ? please ....

Thanks..
# 2  
Old 04-24-2009
Lightbulb Try This:

Code:
#!/bin/sh

i=0
cat input | while read line
do
   case $i in
      0) str1=`echo $line | awk -F'#' '{print $2}'`;;
      1) str2=`echo $line | awk -F'ON' '{print $2}'`;;
      2) str3=`echo $line | awk -F'AT' '{print $2}'`;;
      3) str4=`echo $line | awk -F'PRIORITY' '{print $2}'`;;
      4) i=0;
         str=`echo $str1 \| $str2 \| $str3 \| $str4`;
         echo $str;;
   esac
   i=`expr $i + 1`
done

Output:
JOBCOUNT | EVERYDAY | 0000 | 50
JOBCOUNT | EVERYDAY | 0001 | 29
JOBCOUNT | EVERYDAY | 0002 | 40

Hope this helps.
# 3  
Old 04-24-2009
With one awk command:

Code:
awk -F" |#" '/^SCHEDULE/{
  s=$3
  getline;s=s"|"$NF
  getline;s=s"|"$NF
  getline;s=s"|"$NF
  print s
}' file

# 4  
Old 04-24-2009
/usr/xpg4/bin/awk '/PRIORITY/{print;next}NF{printf("%s ",$0)}' file |cut -d "#" -f2 | cut -d ' ' -f1,3,5,7 |awk -F" " '{print $1 , "|"$2 ,"|"$3 ,"|"$4}'
# 5  
Old 04-24-2009
Yet another one with awk:

(use gawk, nawk or /usr/xpg4/bin/awk on Solaris)

Code:
awk '{ sub(/.*#/, ""); $0 = $NF }
ORS = NR % 4 ? OFS : RS' OFS=\| infile

# 6  
Old 04-29-2009
Thank you all.....
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract data from a log file and put it in a file

Hi, I would like to seek your help for a script that will extract data from log file and put it in a file. Sample log file 2018-10-23 12:33:21 AI ERROR -- tpid: SAMPLE_TH account: 123456789 aiSessionNumber: 660640464 mapName: xxx to yyy errorDesc: Translation Error:ErrorNumber : 993 ... (2 Replies)
Discussion started by: neverwinter112
2 Replies

2. Shell Programming and Scripting

Visit site get data and put in file for use.

I need to go to "vpnbook"vpnbook.com on the web (can't put in name yet)and open "Openvpn" tab On that page I need to get the username:vpnbook and the next line password:???????? I need to put those two in line one and two of a file "pwfile" When I have those I need to open openVPN with the... (1 Reply)
Discussion started by: tytower
1 Replies

3. Shell Programming and Scripting

How to grep/sed selected data from a command or file?

Below is the output of a DB2 command. Now I have 2 requirements... Database Partition 0 -- Database TESTDB1 -- Active Standby -- Up 213 days 02:33:07 -- Date 02/22/2016 17:04:50 HADR Information: Role State SyncMode HeartBeatsMissed LogGapRunAvg (bytes) Standby ... (2 Replies)
Discussion started by: rlokesh27
2 Replies

4. Shell Programming and Scripting

Formatting data to put it in the excel file

Hello, I have a file with the below contents : Policy Name: Backup_bkp Policy Type: Catalog_bkp Active: yes Effective date: 08/07/2013 02:02:12 Mult. Data Streams: no Client Encrypt: no Checkpoint: no Policy Priority: ... (11 Replies)
Discussion started by: rahul2662
11 Replies

5. Shell Programming and Scripting

Read file and get the data then put it in array

Hi, I have a file called "readfile" it contains below parameters #cat readfile word=/abc=225,/abc/cba=150 three=12 four=45 five=/xyz/yza likewise multiple line. From the above file, I have to read "word" output should be like, /abc /abc/cba these values need to be put in... (3 Replies)
Discussion started by: munna_dude
3 Replies

6. Shell Programming and Scripting

Get Data From CSV File and put into a txt file

Hi Guys, File A I have File A as CSV Format.... No R SS MK Par value S AL A1 PKL123 Lo12 1 S AL A2 PKl123 Lo34 22 S AL A3 PkLK234 Lo67 -34 S AL A4 PkLK235 Lo09 120 S AL A5 PkLK236 Lo76 19 S AL A6 PkLK237 Lo44 -17 S AL A7 PkLK238 Lo90 2 S AL A8 PkLK239 Lo34 -9 I want file B like... (4 Replies)
Discussion started by: asavaliya
4 Replies

7. Shell Programming and Scripting

split input data file and put into same output file

Hi All, I have two input file and need to generate a CSV file. The existing report just "GREP" the records with the Header and Tailer records with the count of records. Now i need to split the data into 25 records each in the same CSV file. id_file (Input file ) 227050994 232510151... (4 Replies)
Discussion started by: rasmith
4 Replies

8. UNIX for Advanced & Expert Users

filter last 24 hour data and put in new file

i have file server 1 (filesvr01acess.log) and disc server 1 (discsvr01acess.log) in unix box(say ip adress of the box 10.39.66.81) Similiarly i have file server 2 (filesvr01acess.log) and disc server 2(discsvr01acess.log) in another unix box(say ip adress of the box 10.39.66.82). Now my... (1 Reply)
Discussion started by: nripa1
1 Replies

9. Shell Programming and Scripting

Read a file and put it in HTML format

Hi, I have one file as follows and I need to read this file contents in an HTML format. And send html file to some mail ids using sendmail. Communications Pvt Ltd Report AccountId Name Code IdBill Balance ... (3 Replies)
Discussion started by: Kattoor
3 Replies

10. UNIX for Dummies Questions & Answers

How to copy data file from UNIX and put it on PC

Hello, My customer wants me to copy a data file from his UNIX box, and transfer to windows basic PC. My question is how can I find the file in UNIX box, copy it out into DOS/Windows format. Please help. Thanks (3 Replies)
Discussion started by: BillyT
3 Replies
Login or Register to Ask a Question