Shell to display portion of a line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell to display portion of a line
# 1  
Old 10-30-2013
Shell to display portion of a line

Thanks a lot for the code and the explanation.

Now my final requirement.

I have uploaded 3 files as attachment. Please open the files in Editplus or any other text editor which keeps the formatting.

GMDCOM.27936.log.txt------I want to pick only Process request from this file.(Please check the fourth line of the file)
e.g: Process Request <36812974>
Search the above process request number (in this case 36812974) in GMDRRS.27895.log.txt file and again search it in GMDRES.28009.log.txt file.

Wherever it matches the above process request in all the 3 files. Please display the same in another file along with date, time and process request number.
It has to be done for all the Process Request number in GMDCOM.27936.log.txt file.

Output to be in the below format.
Code:
          Request ID                             GMDCOM                           GMDRRS                    GMDRES
Procs.Req No              Date        Time                 Date                     Time                     Date Time

Hope I am clear with the requirement. If there are any issues, please let me know.

Last edited by Scrutinizer; 10-30-2013 at 03:10 AM.. Reason: Formatting not clear; code tags
# 2  
Old 10-30-2013
What have you tried so far?
# 3  
Old 10-30-2013
Shell to display portion of a line

1st I am trying to display all the lines from GMDCOM.27936.log.txt in the below format.

Code:
[36812974    [Tue Oct  1 13:32:40 2013]]

How do i display all the records from the file GMDCOM.27936.log.txt in the above format. File is attached in the previous post.


I was trying the below code. but its not working.

Code:
cat $file | cut -d ' ' -f 10

Code:
awk 'NR==1 { print 36812974:", $1, $2, $3 } ' trial


Last edited by ghosh_tanmoy; 10-30-2013 at 04:36 AM.. Reason: What i tried.
# 4  
Old 10-30-2013
Could you give a more specific sample of the output that you are looking for?
# 5  
Old 10-30-2013
Shell to display portion of a line

Sample Input File

Code:
[Tue Oct  1 13:28:23 2013]: file reopened from GMDCOM with PID <27936>.
[Tue Oct  1 13:28:23 2013]: GMDCOM: Process <27936> created a running file.
GMDCOM [Tue Oct  1 13:28:24 2013]: DELTA MODE Flag OFF!
GMDCOM.27936 [Tue Oct  1 13:32:40 2013]: Process Request <36812974>
GMDCOM.27936 [Tue Oct  1 13:37:38 2013]: Process Request <36812985>
GMDCOM.27936 [Tue Oct  1 13:37:53 2013]: Process Request <36812986>
GMDCOM.27936 [Tue Oct  1 13:37:54 2013]: Process Request <36812987>
GMDCOM.27936 [Tue Oct  1 13:37:57 2013]: Process Request <36812996>
GMDCOM.27936 [Tue Oct  1 13:38:06 2013]: Process Request <36812998>

I want the output in the below format by skipping the 1st 3 lines
Code:
36812974 [Tue Oct  1 13:32:40 2013]
36812985 [Tue Oct  1 13:37:38 2013]
36812986 [Tue Oct  1 13:37:53 2013]

and it goes on like this till the end of the file. How will it display all the records in the above format. Please help.
# 6  
Old 10-30-2013
But that contradicts your previous attempts at output specifications in both posts #1 and posts #3. Please clarify..
# 7  
Old 10-30-2013
Requirement changed a bit.

The output requirement changed a bit, hence requested for the change in formatting.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extract a portion of string from each line in Linux

Hi I have to extract the destination path information from each record the file is of variable length so I will not be able to use the print command.The search should start on variable "destinationPath" and it should end at immediate "," also the first field has to be printed Input File:... (7 Replies)
Discussion started by: rkakitapalli
7 Replies

2. Shell Programming and Scripting

How to grep a portion of line

Mysql log has something like: I want to grep only the portion "ernie-1328697839.1233158" from each line. How to do this? (6 Replies)
Discussion started by: proactiveaditya
6 Replies

3. Shell Programming and Scripting

Print portion line in SED

Hi, This is more a theoretical question, because I usually solved that with perl or even java, but I would like to know if it exists an easy way to do it with SED. Using regular expresions it's very easy to select an portion line. Does it exist an easy way for printing those portions in SED?... (1 Reply)
Discussion started by: islegmar
1 Replies

4. Shell Programming and Scripting

Print a portion of a line

Hi, I am facing a little problem... I have a line like this : asdcvashfasashXXXXxxxzxcadd:sdcashjqdasdsmgdkdaxdsnd; I want to print just a portion of line i.e starting from left 5 characters from ":" and upto ";" i.e. in this case it would be "xcadd:sdcashjqdasdsmgdkdaxdsnd;" The length of... (2 Replies)
Discussion started by: vanand420
2 Replies

5. Shell Programming and Scripting

Delete a portion of a line using shell scripting

Hi all, I am new to awk programs.I have a file like this 1234567@2345||adcbdefhij: asgdfdasdfhhfd-asdfasd-dsfasdf |0.678|0.0|0.213 1234567@2345||adcbdefhij: ashhfd-asdfasd-dsfasdf |0.129|0.0|0.411 1234567@2345||adcbdefhij: asd-aasd-dasdf |0.223|0.0|0.276 I want to delete the text which... (3 Replies)
Discussion started by: Loy81
3 Replies

6. UNIX for Dummies Questions & Answers

Cutting a portion of a line seperated by pipe delimiter

Hi, In the below line a|b|10065353|tefe|rhraqs|135364|5347575 dgd|rg|4333|fhra|grhrt|46423|urdsgd Here i want to cut the characters in between the second and third pipe delimiter and then between fifth and sixth delimiter and retain the rest of the line. My output should be ... (3 Replies)
Discussion started by: ragavhere
3 Replies

7. Shell Programming and Scripting

awk program to select a portion of a line

Hi all, I am new to awk programs.I have a file like this vjfavhjlaf<LTEXT>aabcdfffvvbbxbcddjbv</LTEXT>fAFdfdADfd vjfavhjlaf<LTEXT>aabcdfffvvbbxbcddjbv</LTEXT>fAFdfdADfd vjfavhjlaf<LTEXT>aabcdfffvvbbxbcddjbv</LTEXT>fAFdfdADfd vjfavhjlaf<LTEXT>aabcdfffvvbbxbcddjbv</LTEXT>fAFdfdADfd... (3 Replies)
Discussion started by: anju
3 Replies

8. UNIX for Dummies Questions & Answers

display a portion of lines from file

This is truly dummy question. I have a text file of 100 lines. What unix commnad to extract line 20 to 40 and output it to another file? Is it something cat or grep or >> ? Thanks (6 Replies)
Discussion started by: champion
6 Replies

9. UNIX for Dummies Questions & Answers

erasing portion of line with sed (only once)

hi, I'm trying to use sed to erase everything, up to the first parenthesis. for example: input: blah blah blah (aldj) test (dafs) test test. output: (aldj) test (dafs) test test. how would i do this? I was fooling around with the parenthesis, and i only got it to apply on all parenthesis.... (1 Reply)
Discussion started by: gammaman
1 Replies

10. UNIX for Dummies Questions & Answers

erasing portion of line with sed

hi, I'm trying to use sed to erase everything, and including the ending parenthesis. For example: input: blah blah blah (12355)this is what i want. output: this is what i want. how would i do this? i found an example online that does the opposite: sed \"s|test.*||g\" file1 > file2"; ... (5 Replies)
Discussion started by: gammaman
5 Replies
Login or Register to Ask a Question