Visit Our UNIX and Linux User Community

Merge all commands into one

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Merge all commands into one
# 1  
Old 09-30-2009
Merge all commands into one

how can i merge follwoing process to one...

tail +5 rawdata_AAA_1.txt_$$ | grep -v "^$" >> rawdata_AAA_2.txt_$$

For discarding first 5 rows and deleting null rows
awk '!/^ /{if(a) print a; a=$0}/^ /{print a}' rawdata_AAA_2.txt >> rawdata_AAA_3.txt

For merging record if it split into 2 rows
awk '$2 != "" {print}' rawdata_AAA_3.txt_$$ | sort | uniq  >> rawdata_AAA_4.txt_$$

For sorting and removing duplicate data
awk '{print "AAA "$0}' rawdata_AAA_4.txt >> final_rawdata.txt

For adding column at first in the file..

How can i club all this process into one command?
# 2  
Old 09-30-2009
Just post a sample data and an example of the desired output.
# 3  
Old 09-30-2009
I'm not sure to understand your merge command. Seems that for lines starting with a space the command prints the last lines not starting with a space.

Please give us an example of input and output datas.

# 4  
Old 09-30-2009
Below if same data in my file

Job Name                        Last Start        Last End     ST  Run  Pri/Xit
____________________________ ________________ ________________ __ _______ ___

35111_AAA         -----            -----            OI 0/0
  35111_BBB        -----            -----            IN 0/0
35111_CCC               09/01/2009 08:57 09/01/2009 08:57 FA 55556015/1 1

                             -----            -----            OI 0/0

                             03/20/2008 11:27 03/20/2008 11:40 SU 38917388/2
35111_FFF         -----            -----            OI 0/0

35111_GGG         -----            -----            OI 0/0

I want data in following format

AAA  35111_AAA         -----            -----            OI 0/0
AAA  35111_BBB        -----            -----            IN 0/0
AAA  35111_CCC   09/01/2009 08:57 09/01/2009 08:57 FA 55556015/1 1
AAA  35111_DDD   -----            -----            OI 0/0
AAA  35111_EEE   03/20/2008 11:27 03/20/2008 11:40 SU 38917388/2
AAA  35111_FFF       -----            -----            OI 0/0
AAA  35111_GGG         -----            -----

# 5  
Old 09-30-2009
Compose all these commands into a shell script. Thats all ?! Or clarify better why you want all these to be clubbed in to single command ?
# 6  
Old 09-30-2009
Why don't you merge the two following lines (the second line starts with spaces) ?
35111_AAA         -----            -----            OI 0/0
  35111_BBB        -----            -----            IN 0/0

# 7  
Old 09-30-2009
You can start with:

awk 'END { print r }
$1 ~ /_/ && r { print r }
NR > 3 && NF { 
  $1 = $1
  r = (split($1, t, "_") > 1 ? t[2] : r) FS $0
  }' infile

Use gawk, nawk or /usr/xpg4/bin/awk on Solaris.

No sort/unique for now, just trying to format the text as of your last post.
P.S. Squeezed the white space characters, not sure if you want that, though ...

---------- Post updated at 05:25 PM ---------- Previous update was at 05:16 PM ----------

Oops, just saw you have only an "AAA" in your first column, is that correct?

Last edited by radoulov; 09-30-2009 at 12:22 PM..

Previous Thread | Next Thread
Test Your Knowledge in Computers #595
Difficulty: Medium
In C, the starting point in the executable program is the prime() function.
True or False?

10 More Discussions You Might Find Interesting

1. Programming

Merge .lo into .so

Good day to everyone. I've built an libxml2 from sources. I can not install it in a proper way with using repository due to I have not sudo privilegies. I've got a set of .lo files. Is there a simple way to merge it in one .so or .a file? (2 Replies)
Discussion started by: z7ql
2 Replies

2. Shell Programming and Scripting

How to merge two files?

Hi Gurus, I have two files as below file1 abc cde cdd cdf file2 123 234 345 456 I want to get abc 123 cde 234 cdd 345 (3 Replies)
Discussion started by: ken6503
3 Replies

3. Shell Programming and Scripting

Merge output of 2 commands into variable

I am extracting two pieces of information from the following file: /proc/cpuinfo, that I need to merge into one report. The first command: grep -i processor /proc/cpuinfo | awk '{print $1$2,$3}' yields: processor: 0 processor: 1 processor: 2 processor: 3 The second command: grep -i... (4 Replies)
Discussion started by: jamarsh
4 Replies

4. UNIX for Advanced & Expert Users

How to merge two commands

I have input like Unload: 2610000 225 2198 374 315 420 1149 57 2611 595 662 374 820 130 2938 486 2483 397 760 using these values, i need to divide first number with second number, means 225/2198, and using the value i'm trying to sort it. After sort i need first and "Unload" values,... (2 Replies)
Discussion started by: arivu198314
2 Replies

5. AIX

HACMP: difference between 'cl' commands and 'cli' commands

Hi all, I'm new in this forum. I'm looking for the difference between the HACMP commands with the prefix "cl" and "cli". The first type are under /usr/es/sbin/cluster/sbin directory and the second are under /usr/es/sbin/cluster/cspoc directory. I know that the first are called HACMP for AIX... (0 Replies)
Discussion started by: peppix
0 Replies

6. Shell Programming and Scripting

merge two file

how to merge two file, i have 2 input file; file_1 & file_2, so i want the output file_3 as below file_1 NAME aa 111 222 bb.txt 111 222 cc 111 111 dd 222 ee 111 222 (4 Replies)
Discussion started by: zulabc
4 Replies

7. Shell Programming and Scripting

merge files

hi, i've two files whcih i need to merge in below format. File1- DEFINE lc_driver CHAR(3) INITIALIZE gr_XXX_MAIN_TABLE_XXX.* TO NULL { EXECUTE p_XXX_MAIN_TABLE_XXX_ins USING gr_XXX_MAIN_TABLE_XXX.* } File2 - # field1 LET table1.field1= (8 Replies)
Discussion started by: dvah
8 Replies

8. UNIX for Dummies Questions & Answers

awk simple commands merge

Is there nice awk code for merging the following commands and do the last task? input1 ab100 xxx 100 blahblah + 1000 ab100 yyy 90 blahblah + 1000 ef390 ggg 200 blahblah - 2000 ef390 aaa 100 blahblah - 2000 df888 ttt 300 ... (5 Replies)
Discussion started by: ruby_sgp
5 Replies

9. Shell Programming and Scripting

Can BASH execute commands on a remote server when the commands are embedded in shell

I want to log into a remote server transfer over a new config and then backup the existing config, replace with the new config. I am not sure if I can do this with BASH scripting. I have set up password less login by adding my public key to authorized_keys file, it works. I am a little... (1 Reply)
Discussion started by: bash_in_my_head
1 Replies

10. Programming

code that reads commands from the standard i/p and executes the commands

Hello all, i've written a small piece of code that will read commands from standard input and executes the commands. Its working fine and is execting the commands well. Accepting arguments too. e.g #mkdir <name of the directory> The problem is that its not letting me change the directory i.e... (4 Replies)
Discussion started by: Phrozen Smoke
4 Replies

Featured Tech Videos