Sponsored Content
Top Forums Shell Programming and Scripting Sed Awk Cut Grep Combination Help ? Post 302294822 by ripat on Friday 6th of March 2009 02:34:04 AM
Old 03-06-2009
If your awk version supports the sub() string function *and* if your record always have the same layout, here is another way of doing it:

Code:
awk  'BEGIN{RS="\n\n"; FS="\n"}{sub(/^.+State/, "State", $2); sub(/Max.+$/, "", $14); print $1,$2,$14}' file

Or, if you hate the one-liner style of coding:
Code:
awk  '
BEGIN{
	RS="\n\n"
	FS="\n"
}
{
	sub(/^.+State/, "State", $2)
	sub(/Max.+$/, "", $14)
	print $1,$2,$14
}' file

Edit: By reading the OP, I just realized that I stopped at the first request. So, go for the Radoulov's snippet. I can't think of anything better.

Last edited by ripat; 03-06-2009 at 03:44 AM..
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed, grep, cut or combine?

I am a beginner at shell scripting, actually i am working on my first script right now. Anyway i have searched the world how to grep two letters from each word (it will always just be two words). For example: Example Blablabla I want my script to cut out Ex (from the first word) and Bl... (4 Replies)
Discussion started by: maskot
4 Replies

2. Shell Programming and Scripting

cut sed grep or other?

Hi Is there a way to cut the last two characters off a word or number given that this word or number can be of varying length? I have tried something like TEST=`echo $OLD | cut -c 1-5` where $OLD is a variable containing a number like 1234567 which gives a result of 12345. This is fine... (4 Replies)
Discussion started by: rleebife
4 Replies

3. Shell Programming and Scripting

cut in sed/awk

Hi Can i have an example where i should be able to cut columns (like for eg cut -c 1-3) in sed or awk. Regards Dhana (12 Replies)
Discussion started by: dhanamurthy
12 Replies

4. UNIX for Dummies Questions & Answers

Awk/sed solution for grep,cut

Hi, From the file "example" with lines like below, I need the int value associated with ENG , i.e, 123 SUB: ENG123, GROUP 1 SUB: HIS124, GROUP 1 .. .. Normally , i do grep ENG example | cut -d ' ' -f 2 | cut -c 4-6 Is it possible to do it in simpler way using awk/sed ? ... (5 Replies)
Discussion started by: priyam
5 Replies

5. Shell Programming and Scripting

Using grep and cut within awk

Hi My input file looks like as follows: say a.txt "aaaa cc","224 AW","ss cccccc","P06 09/10","dddddd" "aaaa cc","224 AW","ss cccccc","P06 09/10","dddddd" "aaaa cc","224 AW","ss cccccc","P06 09/10","dddddd" "aaaa cc","224 AW","ss cccccc","P06 09/10","dddddd" "aaaa cc","224 AW","ss... (5 Replies)
Discussion started by: bittoo
5 Replies

6. Shell Programming and Scripting

Advice using cut & echo combination commands

Hi, I am cutting data from a fixed length test file and then writing out a new record using the echo command, the problem I have is how to stop multiple spaces from being written to the output file as a single space. Example: cat filea | while read line do field1=`echo $line | cut -c1-2` ... (6 Replies)
Discussion started by: dc18
6 Replies

7. Shell Programming and Scripting

GREP/CUT/AWK to Arrays

hi people, I have a text file containing data, seperated by TAB. I want to process this tab'ed data as variable. how can I assign this? Ex: Code: 11aaa 12000 13aaa 14aaa 15aaa 16aaa 17aaa 21aaa 22000 23aaa 24aaa 25aaa 26aaa 27aaa 31aaa 32000 33aaa 34aaa 35aaa 36aaa 37aaa... (1 Reply)
Discussion started by: gc_sw
1 Replies

8. Shell Programming and Scripting

Using a combination of sort/cut/grep/awk/join/paste/sed

I have a file and need to only select users that have a shell of “/bin/bash” in the line using awk or sed please help (4 Replies)
Discussion started by: boyboy1212
4 Replies

9. UNIX for Dummies Questions & Answers

Print/cut/grep/sed/ date yyyymmdd on the filename only.

I have this filename "RBD_EXTRACT_a3468_d20131118.tar.gz" and I would like print out the "yyyymmdd" only. I use this command below, but if different command like cut or print....etc. Thanks ls RBD_EXTRACT* | sed 's/.*\(........\).tar.gz$/\1/' > test.txt (9 Replies)
Discussion started by: dotran
9 Replies
State(3)						User Contributed Perl Documentation						  State(3)

NAME
State - A package to keep track of plotting commands SYNOPSIS
use PDL::Graphics::State; DESCRIPTION
This is a very simple, at present almost trivial, package to keep track of the current set of plotting commands. USAGE
You create a new object by calling the "new" operator $state = PDL::Graphics::State->new(); Then for each new command you call "add" on this object so that for a call to "line" of the form line $x, $y, $opt; the call to "add" would be like $state->add(&line, 'line', [$x, $y], $opt); which is stored internally as: [&line, 'line', [$x, $y], $opt] The state can later be extracted using "get" which returns the state object which is an array of anonymous arrays like the one above where the first object is a reference to the function, the second an anomymous array of arguments to the function and finally an anonymous hash with options to the command. If you know the order in which you inserted commands they can be removed by calling "remove" with the number in the stack. No further interaction is implmented except "clear" which clears the stack and "copy" which returns a "deep" copy of the state. AUTHOR
Jarle Brinchmann (jarle@astro.ox.ac.uk) after some prodding by Karl Glazebrook. All rights reserved. There is no warranty. You are allowed to redistribute this software / documentation under certain conditions. For details, see the file COPYING in the PDL distribution. If this file is separated from the PDL distribution, the copyright notice should be included in the file. perl v5.8.0 2001-09-26 State(3)
All times are GMT -4. The time now is 01:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy