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
wnn_cvt_xim_tbl(4)						   File Formats 						wnn_cvt_xim_tbl(4)

NAME
wnn_cvt_xim_tbl - Key conversion table for xjsi SYNOPSIS
/usr/lib/locale/ja/wnn/cvt_xim_tbl DESCRIPTION
cvt_xim_tbl defines the conversion table for keyboard input and key code.xjsi(1) converts keyboard input (KeySym) to code (Wnn_code) by using of cvt_key_tbl. SYNTAX State-or-KeySym Wnn_code State-or-KeySym = [States]KeySym-name States = State-name | [SState-or-KeySym and Wnn_code must be separated with a space character or tab. Lines beginning with a semicolon (;) are comments. CODE DESCRIPTION Octal number 0?? Decimal number ?? Hexadecimal number 0x?? or 0X?? EXAMPLES
Example 1: Meta|Left 0x9A Meta|Up 0x99 Meta|F11 0x95 Meta|minus 0x81 Meta|asciicircum 0x82 Kanji 0x81 F1 0x91 F2 0x90 Meta|Shift|F1 0x91 SEE ALSO
xjsi(1), uumkey(4), wnn_2A_CTRL(4) NOTES
Code converted by cvt_xim_tbl is evaluated by the Automaton table 2A_CTRL (default) and then by uumkey. SunOS 5.10 10 Jan 2003 wnn_cvt_xim_tbl(4)
All times are GMT -4. The time now is 04:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy