Sponsored Content
Top Forums Shell Programming and Scripting Remove white space at the beginning of lines Post 302231538 by tipi on Tuesday 2nd of September 2008 02:40:14 PM
Old 09-02-2008
Remove white space at the beginning of lines

Hi!

I store some data obtained with grep or awk in a file. The problem is that some lines have white space at the begining :

[w h i t e s p a c e]line1
line2
[whitespace]line3

I use something like
grep WORD INFILE >> OUTFILE
awk [script] >> OUTFILE

I would love if it were possible to remove the white whitout parsing the OUTFILE after the grep or awk command. Is there an option like I could put in the grep or awk saying "keep only what is at left of the white space"?

Any better idea?

Thanks a lot,

Tipi
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Add new lines with a space in beginning

Hi file1.txt contains GigabitEthernet1/1 GigabitEthernet1/2 GigabitEthernet2/2 GigabitEthernet2/4 GigabitEthernet2/14 GigabitEthernet2/16 can anyone show me how to modify it as below. there is a space at the beginning of the next two lines . ie 'no shut' and 'switch..' !... (8 Replies)
Discussion started by: Aejaz
8 Replies

2. UNIX for Dummies Questions & Answers

SED with White Space

Dear Members, Suppose i have a variable test which stores a string as below: test='John drives+++++++++a+++++car' now i want to use sed on the above variable and replace + with a white space, so that i get echo $test should give me 'john drives a car' Between... (1 Reply)
Discussion started by: sandeep_1105
1 Replies

3. Shell Programming and Scripting

Extract lines between 2 strings add white space

I'm trying to extract all the lines between 2 strings (including the lines containing the strings) To make the strings unique I need to include white space if possible. I'm not certain how to do that. sed -n '/ string1 /,/string2/p' infile > outfile & (4 Replies)
Discussion started by: dcfargo
4 Replies

4. Shell Programming and Scripting

How to remove white spaces from the beginning an end of a string in unix?

Suppose, I have a variable var=" name is ". I want to remove the blank spaces from the begining and endonly, not from the entire string. So, that the variable/string looks like following var="name is". Please look after the issue. (3 Replies)
Discussion started by: mady135
3 Replies

5. Shell Programming and Scripting

remove white space from specific columns in text file

Hello i have a text file like this: 1 AB AC AD EE 2 WE TR YT WW 3 AS UY RF YT the file is bigger , but that's an example of the data what i want to do is to merge all columns together except the first one, it will become like this : 1 ABACADEE 2 WETRYTWW 3 ASUYRFYT (8 Replies)
Discussion started by: shelladdict
8 Replies

6. Shell Programming and Scripting

Remove unwanted white space

Hi, I have a very big file 25GB with information present in it like $ head ind_stats update index statistics pfirm001.dbo.Office using 200 values go ... (11 Replies)
Discussion started by: sam05121988
11 Replies

7. Shell Programming and Scripting

Remove certain lines from file based on start of line except beginning and ending

Hi, I have multiple large files which consist of the below format: I am trying to write an awk or sed script to remove all occurrences of the 00 record except the first and remove all of the 80 records except the last one. Any help would be greatly appreciated. (10 Replies)
Discussion started by: nwalsh88
10 Replies

8. Shell Programming and Scripting

Remove white space and duplicate headers

I have a file called "dsout" with empty rows and duplicate headers. DATE TIME TOTAL_GB USED_GB %USED --------- -------- ---------- ---------- ---------- 03/05/013 12:34 PM 3151.24316 2331.56653 73.988785 ... (3 Replies)
Discussion started by: Daniel Gate
3 Replies

9. Shell Programming and Scripting

Add white space

hi guys how can i add spacein file name with sed if strings have no space around dash input 19-20 ( 18-19 ) ABC-EFG output after add white space 19 - 20 (18 - 19 ) ABC - EFG thx in advance (2 Replies)
Discussion started by: mhs
2 Replies

10. Shell Programming and Scripting

Remove of white space when you have multiple column

i have file in which i want to remove white space from each column where ever it exist there is white space at the end of line. i know how to remove white space if i have only 1 column, but i have multiple columns and white space can be in any column. sed 's/ *$//' file ath-miRf10005-akr... (5 Replies)
Discussion started by: mirwasim
5 Replies
FILTERDIFF(1)															     FILTERDIFF(1)

NAME
filterdiff - extract or exclude diffs from a diff file SYNOPSIS
filterdiff [-i PATTERN] [-p n] [--strip=n] [--addprefix=PREFIX] [-x PATTERN] [--verbose] [-v] [-z] [-# RANGE | --hunks=RANGE] [--lines=RANGE] [--annotate] [--format=FORMAT] [--as-numbered-lines=WHEN] [file...] filterdiff {--help | --version | --list | --grep ...} DESCRIPTION
You can use filterdiff to obtain a patch that applies to files matching the shell wildcard PATTERN from a larger collection of patches. For example, to see the patches in patch-2.4.3.gz that apply to all files called lp.c: filterdiff -z -i '*/lp.c' patch-2.4.3.gz If neither -i nor -x options are given, -i '*' is assumed. To remove lines from a file that are not part of a patch, you might do this: filterdiff message > patch Note that the interpretation of the shell wildcard pattern does not count slash characters or periods as special (in other words, no flags are given to fnmatch). This is so that ``*/basename''-type patterns can be given without limiting the number of pathname components. You can use both unified and context format diffs with this program. OPTIONS
-i PATTERN Include only files matching PATTERN. All other lines in the input are suppressed. -x PATTERN Exclude files matching PATTERN. All other lines in the input are displayed. -p n When matching, ignore the first n components of the pathname. -# RANGE | --hunks=RANGE Only include hunks within the specified RANGE. Hunks are numbered from 1, and the range is a comma-separated list of numbers or ``first-last'' spans; either the first or the last in the span may be omitted to indicate no limit in that direction. --lines=RANGE Only include hunks that contain lines from the original file that lie within the specified RANGE. Lines are numbered from 1, and the range is a comma-separated list of numbers or ``first-last'' spans; either the first or the last in the span may be omitted to indi- cate no limit in that direction. --annotate Annotate each hunk with the filename and hunk number. --format=unified|context Use specified output format. --strip=n Remove the first n components of pathnames in the output. --addprefix=PREFIX Prefix pathnames in the output by PREFIX. --as-numbered-lines=before|after Instead of a patch fragment, display the lines of the selected hunks with the line number of the file before (or after) the patch is applied, followed by a TAB character and a colon, at the beginning of each line. Each hunk except the first will have a line con- sisting of ``...'' before it. -v, --verbose Always show non-diff lines in the output. By default, non-diff lines are only shown when excluding a filename pattern. -z Decompress files with extensions .gz and .bz2. --help Display a short usage message. --version Display the version number of filterdiff. --list Behave like lsdiff(1) instead. --grep Behave like grepdiff(1) instead. EXAMPLES
To see all patch hunks that affect the first five lines of a C file: filterdiff -i '*.c' --lines=-5 < patch To see the first hunk of each file patch, use: filterdiff -#1 patchfile To see patches modifying a ChangeLog file in a subdirectory, use: filterdiff -p1 Changelog To see the complete patches for each patch that modifies line 1 of the original file, use: filterdiff --lines=1 patchfile | lsdiff | xargs -rn1 filterdiff patchfile -i To see all but the first hunk of a particular patch, you might use: filterdiff -p1 -i file.c -#2- foo-patch If you have a very specific list of hunks in a patch that you want to see, list them: filterdiff -#1,2,5-8,10,12,27- To see the lines of the files that would be patched as they will appear after the patch is applied, use: filterdiff --as-numbered-lines=after patch.file You can see the same context before the patch is applied with: filterdiff --as-numbered-lines=before patch.file Filterdiff can also be used to convert between unified and context format diffs: filterdiff -v --format=unified context.diff SEE ALSO
lsdiff(1), grepdiff(1) AUTHOR
Tim Waugh <twaugh@redhat.com>. patchutils 23 Aug 2002 FILTERDIFF(1)
All times are GMT -4. The time now is 04:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy