Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Grep certain lines with condition Post 302803543 by vidyadhar85 on Tuesday 7th of May 2013 04:08:54 AM
Old 05-07-2013
Try below
Code:
 
 sort -n -t, -k 2,2 filename|awk -F, '{A[$1]=$2}END{for (i in A){print i","A[i]}}'

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

grep command with AND condition

I want to do a grep with AND condition. I have three files. file1.txt ======== UNIX ...... WINDOWS ........ ORACLE file2.txt ======== UNIX ....... WINDOWS ...and many such files in a directory (6 Replies)
Discussion started by: prasperl
6 Replies

2. Homework & Coursework Questions

Grep line above X condition

1. The problem statement, all variables and given/known data: I have to grep a data file called datebook.txt. The last information in each line is a salary. I have to grep all the lines which precede those lines with 6 figure salaries. I can't SID it, or use Perl. It has to be grep (or egrep or... (3 Replies)
Discussion started by: DrSammyD
3 Replies

3. Shell Programming and Scripting

grep inside if condition - need help

hi i need help with below code. if ] then log "Exiting the script as ID= NULL" log "Please run script first." fi i am calling grep inside this but its not running any ideas why ?? input file is like this -- Msg 102, Level 20, State 1: Server... (4 Replies)
Discussion started by: dazdseg
4 Replies

4. Shell Programming and Scripting

use awk pick value from lines as condition for grep

Hi Folks! I have a file like this 000000006 dist:0.0 FILE ./MintRoute/MultiHopWMEWMA.nc LINE:305:1 NODE_KIND:131 nVARs:4 NUM_NODE:66 TBID:733 TEID:758 000000000 dist:0.0 FILE ./Route/MultiHopLEPSM.nc LINE:266:1 NODE_KIND:131 nVARs:4 NUM_NODE:66 TBID:601 TEID:626 000000001 ... (2 Replies)
Discussion started by: jackoverflow
2 Replies

5. Shell Programming and Scripting

Perl XML, find matching condition and grep lines and put the lines somewhere else

Hi, my xml files looks something like this <Instance Name="New York"> <Description></Description> <Instance Name="A"> <Description></Description> <PropertyValue Key="false" Name="Building A" /> </Instance> <Instance Name="B"> ... (4 Replies)
Discussion started by: tententen
4 Replies

6. Shell Programming and Scripting

grep in the if condition

Hi, In this code can able to match the pattern without case sensitive. Is that possible? if u knw plz help me... code: echo "Enter name to search" read n if ; echo "name found" else echo "Not Found" fi (8 Replies)
Discussion started by: boopal
8 Replies

7. Shell Programming and Scripting

Where condition in grep or awk?

Dear All, I need help.. I am having a csv file. Home_TITLE,People_TITLE,Repo_ALIAS HMN5530,RKY5807,/mine_repo/rike001 HMN5530,SRY6443,/mine_repo/rike001 HMN5530,ARDY001,/mine_repo/rike001 If i have two value in varible RKY5807, HMN5530. how can fetch and store another value... (6 Replies)
Discussion started by: yadavricky
6 Replies

8. UNIX for Dummies Questions & Answers

How to grep with certain condition?

hi all, i have an xml what i have to do is to search for the source id(s1) and if it matches with that in xml then extract the file mask from the name of the file i.e if the file name is idr_%YYYY%%MM%%DD%_%N%.idr then , i want the part after first % and before last % ie in this case ... (5 Replies)
Discussion started by: ramsavi
5 Replies

9. UNIX for Dummies Questions & Answers

Grep with condition

I have file input AAAA_XX_Start> rlong . 0W 130526-11:36:13 10.128.13.226 9.0j RBS_NODE_MODEL_N_1_50 stopfile=/tmp/13019 .. ================================================================================================================= MO ... (2 Replies)
Discussion started by: radius
2 Replies
fold(1) 						      General Commands Manual							   fold(1)

NAME
fold - Breaks or wraps lines in a file SYNOPSIS
fold [-bs] [-w width | -width] [file...] The fold command wraps lines in the specified files. If a file is not specified, standard input is the default. All lines are wrapped to meet the maximum width specified. STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: fold: XCU5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. OPTIONS
Specifies that width be counted in bytes rather than in column positions. Using the -b option does not limit lines to LINE_MAX bytes. Breaks (or wraps) a line if a segment of the line contains a blank character in the first width column position (or bytes). This enables the line to meet width constraints. If a blank character is not in the correct width column position, the -s option has no affect on that input line. Specifies the maximum width to use when lines are wrapped in column positions (or bytes if the -b option is specified). Either -w width or -width is acceptable input where width is the number of column positions (or bytes). The default value is 80. DESCRIPTION
The fold command is a filter that wraps lines from the specified input files or standard input to a maximum of width (or bytes, if the -b option is specified). The fold command wraps lines by inserting a newline character into the output so that each output line is the maxi- mum column positions or bytes specified. A line cannot be broken in the middle of a character. The fold command is often used to send text files to line printers that truncate, rather than wrap, lines wider than the printer is able to print (usually 80 or 132 column positions). If the <backspace>, <tab>, or <carriage return> characters are encountered in the input, and the -b option is not specified, these charac- ters are treated specially: The current count of line width is decremented by one, although the count never becomes negative. The fold command does not insert a newline character immediately before or after any backspace character. Each tab character encountered advances the column position pointer to the position of the next tab stop. Tab stops are at each column position number, such that number modulo 8 equals 1. The current count of the line width is set to zero (0). The fold command does not insert a newline immediately before or after any carriage return. [Tru64 UNIX] The fold command possibly affects underlining in a file. EXIT STATUS
The fold command returns the following values: All input files were successfully processed. [Tru64 UNIX] A usage error occurred. [Tru64 UNIX] An input file cannot be opened. The fold command continues processing the other input files specified on the command line. EXAMPLES
The fold command can be used to prepare files to be joined side-by-side with the paste command. For example, the contents of two files, az and AZ follows: aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii jjjj kkkk llll mmmm nnnn oooo pppp qqqq rrrr ssss tttt uuuu vvvv wwww xxxx yyyy zzzz AAAA BBBB CCCC DDDD EEEE FFFF GGGG HHHH IIII JJJJ KKKK LLLL MMMM NNNN OOOO PPPP QQQQ RRRR SSSS TTTT UUUU VVVV WWWW XXXX YYYY ZZZZ To display the az and AZ files side-by-side, use the following command line: fold -w 32 az > az2; fold -w 32 AZ > AZ2; paste -d" " az2 AZ2 Executing the previous command line results in the following output: aaaa bbbb cccc dddd eeee ffff gg AAAA BBBB CCCC DDDD EEEE FFFF GG gg hhhh iiii jjjj kkkk llll mmmm GG HHHH IIII JJJJ KKKK LLLL MMMM nnnn oooo pppp qqqq rrrr ssss tt NNNN OOOO PPPP QQQQ RRRR SSSS TT tt uuuu vvvv wwww xxxx yyyy zzzz TT UUUU VVVV WWWW XXXX YYYY ZZZZ ENVIRONMENT VARIABLES
The following environment variables affect the execution of fold: Provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding value from the default locale is used. If any of the internationalization vari- ables contain an invalid setting, the utility behaves as if none of the variables had been defined. If set to a non-empty string value, overrides the values of all the other internationalization variables. Determines the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multibyte characters in arguments) and for the determination of the width in column positions each character would occupy on a constant-width font output device. Determines the locale for the format and contents of diagnostic messages written to standard error. Determines the location of message catalogues for the processing of LC_MES- SAGES. SEE ALSO
Commands: cut(1), expand(1), paste(1) Standards: standards(5) fold(1)
All times are GMT -4. The time now is 02:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy