Sponsored Content
Top Forums Shell Programming and Scripting Shell script to merge and delete lines Post 303026526 by Jag02 on Thursday 29th of November 2018 02:32:11 AM
Old 11-29-2018
Shell script to merge and delete lines

Code:
POLY_STATS   
{     
EqName 103_tri    
Id 123    
act_polyCount 1    
act_polyValue 0    
}     
POLY_STATS
{     
EqName 103_tri    
Id 123    
pass_polyCount 2
pass_polyValue 0    
}     
POLY_STATS
{     
EqName 103    
Id 123    
mes_polyCount 2    
mes_polyValue 0    
}     
POLY_STATS
{   
EqName 504    
Id 123    
mes_polyCount 2    
mes_polyValue 0    
}     
}

My requirement is a shell script to merge the block where the EqName and Id are same and remove the second block.The value of EqName and Id may change. So there should be a dynamic approach to get the value of EqName and Id
The output should be:
Code:
POLY_STATS   
{     
EqName 103_tri    
Id 123    
act_polyCount 1    
act_polyValue 0 
pass_polyCount 2
pass_polyValue 0    
}     
 
POLY_STATS
{     
EqName 103    
Id 123    
mes_polyCount 2    
mes_polyValue 0    
}     
POLY_STATS
{   
EqName 504    
Id 123    
mes_polyCount 2    
mes_polyValue 0    
}     
}

The algorithm i am thinking of is:
Get the value of EqName
Get the value of Id
Match for the second occurence of EqName and Id
Get the two lines below the second occurence of Id and move those two lines after the first occurence of Id.
Delete two lines above and 4 lines below the first occurence of EqName

Is the above algorithm seems good .Can anyone pl. help me with any other oneliners or using awk/sed by which we can do this easily
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell script to merge files

Can anybody help me out with this problem " a shell program that takes one or any number of file names as input; sorts the lines of each file in ascending order and displays the non blank lines of each sorted file and merge them as one combined sorted file. The program generates an error... (1 Reply)
Discussion started by: arya
1 Replies

2. Shell Programming and Scripting

Need Shell Script to delete lines in a file

Hi All, I have a file with 3 columns (Bank Name, Account Number and Amount). My requirement, I need to delete lines using Unix Shell script: 1. Which are having Alphanumeric characters in Account Number (eg. Line3). 2. Which are having 0.00 in amount. (eg. Line4) 3. And also I need to... (4 Replies)
Discussion started by: phani333
4 Replies

3. Shell Programming and Scripting

Help with merge Shell Script

I have a file test.log The content of the file is : a:R_yz:1 a:R_cd:2 a:F_bc:0 a:F_xx:3 b:R_dg:5 b:R_gf:1 b:F_fd:4 I want the output is : :a R_yz 1 3 3 : R_cd 2 : F_bc 0 : F_xx 3 :b R_dg 5 6 4 : R_gf 1 : F_fd 4 (8 Replies)
Discussion started by: mnmonu
8 Replies

4. Shell Programming and Scripting

remove blank lines and merge lines in shell

Hi, I'm not a expert in shell programming, so i've come here to take help from u gurus. I'm trying to tailor a csv file that i got to make it work for the LOAD FROM command. I've a datatable csv of the below format - --in file format xx,xx,xx ,xx , , , , ,,xx, xxxx,, ,, xxx,... (11 Replies)
Discussion started by: dvah
11 Replies

5. Shell Programming and Scripting

How to select/delete some lines in shell?

I need to delete half(approx) the file or select half the file by existence of some character My file looks like 1 2 3 4 . . . 50 . . 100I need to select only 50 to rest of the file or needs to delete the file upto 50. Please help me out.. (6 Replies)
Discussion started by: SujeethP
6 Replies

6. UNIX for Dummies Questions & Answers

How to delete lines above a certin line number in bash shell

Hi, I have written a script that returns the line number of the pattern i want and i stored the line number in a variable(getlinenumber).Now i want to delete all the lines in a file above this line number which is stored in a variable. i am using sed '1,$getlinenumberd' > file1.txt which is... (2 Replies)
Discussion started by: learninguser235
2 Replies

7. Shell Programming and Scripting

How to merge Expect script inside shell script?

Hi I have two scripts one is Expect and other is shell. I want to merge Expect code in to Shell script so that i can run it using only one script. Can somebody help me out ? Order to execute: Run Expect_install.sh first and then when installation completes run runTests.sh shell script. ... (1 Reply)
Discussion started by: ashish_neekhra
1 Replies

8. Shell Programming and Scripting

Bash/shell merge similar lines

Hello, I've been working on a bash script to parse through firewall logs (cisco). I'm nearing the end and have a dilemma. My data looks as such (actual data is several gigs worth of logs - without the headers): sourceIP destinationIP destinationProtocol destinationPort 1.1.1.1 2.2.2.2 ... (2 Replies)
Discussion started by: umang2382
2 Replies

9. Shell Programming and Scripting

Delete all CONSECUTIVE text lines from file shell scripting

Hi I have a text file like below. THe content of the text will vary. Entire text file have four consecutive lines followed with blank line. I want to delete the occurrence of the two consicutive lines in the text file. I don't have pattern to match and delete. Just i need to delete all... (5 Replies)
Discussion started by: RJSKR28
5 Replies

10. UNIX for Beginners Questions & Answers

Merge multi-lines into one single line using shell script or Linux command

Hi, Can anyone help me for merge the following multi-line log which beginning with a " and line ending with ": into one line. *****Original Log***** 087;2008-12-06;084403;"mc;;SYHLR6AP1D\LNZW;AD-703;1;12475;SYHLR6AP1B;1.1.1.1;0000000062;HGPDI:MSISDN=12345678,APNID=1,EQOSID=365;... (3 Replies)
Discussion started by: rajeshlinux2010
3 Replies
SCHEDCTL(8)						    BSD System Manager's Manual 					       SCHEDCTL(8)

NAME
schedctl -- control scheduling of processes and threads SYNOPSIS
schedctl [-A cpus] [-C class] [-P pri] [-t lid] -p pid | command DESCRIPTION
The schedctl command can be used to control the scheduling of processes and threads. It also returns information about the current schedul- ing parameters of the process or thread. Only the super-user may change the scheduling parameters. schedctl can also be used to start a new command using the specified parameters. Available options: -A cpus Set of the processors on which process or thread should run, that is, affinity. Processors are defined as numbers (starting from zero) and separated by commas. A value of -1 is used to unset the affinity. -C class Scheduling class (policy), one of: SCHED_OTHER Time-sharing (TS) scheduling policy. The default policy in NetBSD. SCHED_FIFO First in, first out (FIFO) scheduling policy. SCHED_RR Round-robin scheduling policy. -P pri Priority for the process or thread. Value should be in the range from SCHED_PRI_MIN (0) to SCHED_PRI_MAX (63). Setting of prior- ity for the process or thread running at SCHED_OTHER policy is not allowed. -p pid The target process which will be affected. If the process has more than one thread, all of them will be affected. If -p is not given, a command to execute must be given on the command line. -t lid Thread in the specified process. If specified, only this thread in the process will be affected. May only be specified if -p is also given. EXAMPLES
Show scheduling information about the process whose ID is ``123'': # schedctl -p 123 Set the affinity to CPU 0 and CPU 1, policy to SCHED_RR, and priority to 63 for thread whose ID is ``1'' in process whose ID is ``123'': # schedctl -p 123 -t 1 -A 0,1 -C SCHED_RR -P 63 Run the top(1) command with real-time priority: # schedctl -C SCHED_FIFO top SEE ALSO
nice(1), getpriority(2), setpriority(2), psrset(8), renice(8) HISTORY
The schedctl command first appeared in NetBSD 5.0. BSD
March 21, 2011 BSD
All times are GMT -4. The time now is 08:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy