Visit Our UNIX and Linux User Community


File processing using script needs help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File processing using script needs help
# 1  
Old 10-05-2009
File processing using script needs help

Dear all,

Need help to write the shell script to process the file.

My requirement is script to process the file line by line and count the ids belong to the server name mentioned as in first field.

if
IN-S-BA1 is there count 4 lines and add the end of count echo the first filed and counted lines.

if IN-S-BA1 is 4
end of the count add one more line in file
IN-S-BA1:4

How can i Achieve this

example input file contains like this.

IN-S-BA1:root:account for OS Admin user:false:system,bin,sys,security,cron,audit,lp,
IN-S-BA1:daemon:account for daemon user:false:staff
IN-S-BA1:bin:account for bin user:false:bin,sys,adm
IN-S-BA1:sys:account for sys user:false:sys
IN-S-BA2:root:account for OS Admin user:false:system,bin,sys,security,cron,audit,lp,
IN-S-BA2:daemon:account for daemon user:false:staff
IN-S-BA2:bin:account for bin user:false:bin,sys,adm
IN-S-BA2:sys:account for sys user:false:sys
IN-S-BT1:root:account for OS Admin user:false:system,bin,sys,security,cron,audit,lp,
IN-S-BT1:daemon:account for daemon user:false:staff
IN-S-BT1:bin:account for bin user:false:bin,sys,adm
IN-S-BT1:sys:account for sys user:false:sys
IN-S-BQ1:root:account for OS Admin user:false:system,bin,sys,security,cron,audit,lp,
IN-S-BQ1:daemon:account for daemon user:false:staff
IN-S-BQ1:bin:account for bin user:false:bin,sys,adm
IN-S-BQ1:sys:account for sys user:false:sys
IN-S-BD1:root:account for OS Admin user:false:system,bin,sys,security,cron,audit,lp,
IN-S-BD1:daemon:account for daemon user:false:staff
IN-S-BD1:bin:account for bin user:false:bin,sys,adm
IN-S-BD1:root:account for adm user:false:adm

Outfile to be like below

IN-S-BA1:root:account for OS Admin user:false:system,bin,sys,security,cron,audit,lp,
IN-S-BA1:daemon:account for daemon user:false:staff
IN-S-BA1:bin:account for bin user:false:bin,sys,adm
IN-S-BA1:sys:account for sys user:false:sys
IN-S-BA1:4
IN-S-BA2:root:account for OS Admin user:false:system,bin,sys,security,cron,audit,lp,
IN-S-BA2:daemon:account for daemon user:false:staff
IN-S-BA2:bin:account for bin user:false:bin,sys,adm
IN-S-BA2:sys:account for sys user:false:sys
IN-S-BA2:4
IN-S-BT1:root:account for OS Admin user:false:system,bin,sys,security,cron,audit,lp,
IN-S-BT1:daemon:account for daemon user:false:staff
IN-S-BT1:bin:account for bin user:false:bin,sys,adm
IN-S-BT1:sys:account for sys user:false:sys
IN-S-BT1:4
IN-S-BQ1:root:account for OS Admin user:false:system,bin,sys,security,cron,audit,lp,
IN-S-BQ1:daemon:account for daemon user:false:staff
IN-S-BQ1:bin:account for bin user:false:bin,sys,adm
IN-S-BQ1:sys:account for sys user:false:sys
IN-S-BQ1:4
IN-S-BD1:root:account for OS Admin user:false:system,bin,sys,security,cron,audit,lp,
IN-S-BD1:daemon:account for daemon user:false:staff
IN-S-BD1:bin:account for bin user:false:bin,sys,adm
IN-S-BD1:root:account for adm user:false:adm
IN-S-BD1:4

Pl Help ....

Thanks in advance..

Madhu

Pl Help ....

Thanks in advance..

Madhu
# 2  
Old 10-05-2009
Code:
nawk -F: '
  NR == 1 { last_server = $1 }
{
  this_server = $1
  if ( this_server == last_server )
    s_count ++
  else{
    print last_server":"s_count
    s_count = 1
  }
  print $0
  last_server = $1
} END {
    print last_server":"s_count
} ' infile > outfile

# 3  
Old 10-09-2009
Thanks steady

it is worked...

Thanks once again.

Madhu

Previous Thread | Next Thread
Test Your Knowledge in Computers #3
Difficulty: Easy
'Hello World' is a program only for advanced programmers.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to log file processing details to database table usnig UNIX shell script?

we are getting files on daily basis.we need to process these files. i need a unix shell script where we can count 1-The no of files processed 2-No of data/record processed for each files. The script should log these details into a database table. If there is any error while file... (3 Replies)
Discussion started by: Atul kumar
3 Replies

2. Programming

awk processing / Shell Script Processing to remove columns text file

Hello, I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this : This is the output of ls command : I stored the output in a file filelist 1.1M... (5 Replies)
Discussion started by: ajayram
5 Replies

3. Shell Programming and Scripting

Need help in File Processing Script

I made one script in shell, but it is not running in my server. So i am trying to make perl for the same. Can anyone help me? #!/bin/sh p=`date '+20%y%m%d'` cp Process_*"$p"*.txt /tmp/ cat /tmp/number.txt | egrep -v "Prefix|---|" | sed -e 's/ //g' -e '/^$/d' | nawk -F"->"... (4 Replies)
Discussion started by: lecria
4 Replies

4. Shell Programming and Scripting

File Processing in shell script

i have a file with following type of data abcd : gggggg gggggg ; 1234 gggggg ; 5678 gggggg ; 3434 gggggg ; 6565 gggggg ; 1231 1234 ; vvvv ;Eng=Myfirstname 5678 ; xyzf ;Eng=Mysecondname 3434 ; xyzf ;Eng=Mythirdname 6565 ; xyzf ;Eng=Mysfourthname 1231 ; xyzf ;Eng=Mysfifthname... (7 Replies)
Discussion started by: telangmadhuri
7 Replies

5. Shell Programming and Scripting

2 file processing script in C shell

I want to use an awk for the following scenario but not sure if it will work or not. I have two input file: F1 and F2 F1 02 05 08 F2 00 01 02 03 04 05 06 07 08 09 10 (1 Reply)
Discussion started by: jclanc8
1 Replies

6. Shell Programming and Scripting

Simple Script needed for Processing CSV file perl

I am new to perl, and need a script to pull a CSV file, strip out 2 leading columns, and 2 ending columns, and resave the file in a new location. The file is basic and has less than 10,000 records. Secondly, can I schedule perl scripts to run daily? Can someone provide the basic script to... (1 Reply)
Discussion started by: cobbjob
1 Replies

7. Shell Programming and Scripting

awk, perl Script for processing a single line text file

I need a script to process a huge single line text file: The sample of the text is: "forward_inline_item": "Inline", "options_region_Australia": "Australia", "server_event_err_msg": "There was an error attempting to save", "Token": "Yes", "family": "Family","pwd_login_tab": "Enter Your... (1 Reply)
Discussion started by: hmsadiq
1 Replies

8. Shell Programming and Scripting

KSH script -text file processing NULL issues

I'm trying to strip any garbage that may be at the end of my text file and that part is working. The problem only seems to be with the really long lines in the file. When the head command is executed I am directing the output to a new file. The new file always get a null in the 4096 position but... (2 Replies)
Discussion started by: geauxsaints
2 Replies

9. Shell Programming and Scripting

perl script for file processing

Aim: To scan a file and ignore all characters that has an ASCII value from 0 to 31 and 127 to 255 and accept only those characters having an ASCII between 32 and 126. Script: #!/usr/local/bin/perl $filename = "$ARGV"; if (-e $filename) { open(OUT, "${filename}") || die "can't... (10 Replies)
Discussion started by: SEEHTAS
10 Replies

10. Shell Programming and Scripting

Have a shell script check for a file to exist before processing another file

I have a shell script that runs all the time looking for a certain type of file and then it processes the file through a series of other scripts. The script is watching a directory that has files uploaded to it via SFTP. It already checks the size of the file to make sure that it is not still... (3 Replies)
Discussion started by: heprox
3 Replies

Featured Tech Videos