Sponsored Content
Top Forums UNIX for Beginners Questions & Answers File manipulation place 0 before the number using sed Post 303039601 by RudiC on Thursday 10th of October 2019 04:26:10 AM
Old 10-10-2019
In case there are other occurrences of three letters followed by a space and a digit, you might want to narrow down the search pattern to the locale months:
Code:
sed -r "s/($(locale abmon | tr ';' '|')) ([[:digit:]] )/\1 0\2/g" file

Be aware that you need sed to recognize / handle EREs for this simple tr approach.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

file name Manipulation using sed

Hi, I have a file name, for which I want to strip out the first bit and leave the rest... So I want to take the file name .lockfile-filename.10001 ,strip it and have only filename.10001 ... Thanking you all inadvance, Zak (6 Replies)
Discussion started by: Zak
6 Replies

2. Shell Programming and Scripting

Place number with awk

Hello, if I've a list of number 23 34 56 78 how I can place a sequence of ordinated number in a boundary column so 1 23 2 34 3 56 4 78 Thanks in advance! (3 Replies)
Discussion started by: cv313x
3 Replies

3. Shell Programming and Scripting

Read a number from file and place it back

Hi All, I want to read one number from the file. Only one number will be there in the file. then i have to increment the number in my script and put it back in the same file. Is it possible? Can anybody help me? Thanks, Vinay (6 Replies)
Discussion started by: vinayakatj56
6 Replies

4. Shell Programming and Scripting

File manipulation with AWK and SED

Hello How do i check that correct input files are used while using AWk and SED for file manipulation? e.g awk '/bin/ {print $0 }' shell.txt sed 's/hp/samsung/' printers.txt how do i ensure that the correct input files I am working with are used? (5 Replies)
Discussion started by: Pauline mugisha
5 Replies

5. Shell Programming and Scripting

SED/AWK file read & manipulation

I have large number of data files, close to 300 files, lets say all files are same kind and have extension .dat , each file have mulitple lines in it. There is a unique line in each file containing string 'SERVER'. Right after this line there is another line which contain a string 'DIGIT=0',... (4 Replies)
Discussion started by: sal_tx
4 Replies

6. Shell Programming and Scripting

setter and getter functions for file manipulation with sed

Hi, I would really appreciate some help, I couldn't nail my problem: I would like to create some setter and getter functions to make my life easier. my sample file contains: keyword - some tabs - value - semicolon number 12.1; float .3; double 12; real 12.2324; stuff .234; decimal... (5 Replies)
Discussion started by: Toorop
5 Replies

7. Shell Programming and Scripting

Help with number field manipulation

I have a comma separated file containing numbers, I would like to read the file and divide each number by 1024 and create an output file. Input file : 50312.00,3434.05, ,3433.34,124344.00,434343.00, , , Output file: 49.13,3.35,3.35,0,12.05,424.16,0,0 Please click this link: How to... (2 Replies)
Discussion started by: inditopgun
2 Replies

8. Shell Programming and Scripting

Use GREP to count number of records and place it in a variable

I am trying to count the number of records from different files using grep, and then place the result in a separate variable for each file, so at the end of my shell script, I can sum all the variables and check if the number of records are equal to what I was expecting. It is weird butwc -ldoes... (2 Replies)
Discussion started by: dhruuv369
2 Replies

9. Shell Programming and Scripting

sed flat file manipulation

Hello, I have a large flat file where i need to change data in columns 131-133 based on what is in columns 172-173. I am not sure if I need to read the file line by line and make the change or if I can do this in a single statement. thank you (3 Replies)
Discussion started by: gblmin
3 Replies

10. Shell Programming and Scripting

Zero padding a Number before and after a decimal place

Hi I was hoping someone could help me with a sed script I am trying to write? I am on a Mac running ElCapitan I have some text that I have converted from a pdf that I want to format into an xml file. In the file I have managed to delete all the text I do not need. The text I have left is... (8 Replies)
Discussion started by: Paul Walker
8 Replies
grep(1) 						      General Commands Manual							   grep(1)

NAME
grep, egrep, fgrep - search a file for a pattern SYNOPSIS
Plain call with pattern pattern [file ...] Call with (multiple) -e pattern pattern] ... [file ...] Call with -f file pattern_file] [file ...] Obsolescent: [expression] [file ...] [strings] [file ...] DESCRIPTION
The command searches the input text files (standard input default) for lines matching a pattern. Normally, each line found is copied to the standard output. supports the Basic Regular Expression syntax (see regexp(5)). The option supports Extended Regular Expression (ERE) syntax (see regexp(5)). The option searches for fixed strings using the fast Boyer-Moore string searching algorithm. The and options treat newlines embedded in the pattern as alternation characters. A null expression or string matches every line. The forms and are maintained for backward compatibility. The use of the and options is recommended for portability. Options Extended regular expressions. Each pattern specified is a sequence of one or more EREs. The EREs can be separated by newline characters or given in separate expression options. A pattern matches an input line if any ERE in the sequence matches the contents of the input line without its trailing newline character. The same functionality is obtained by using Fixed strings. Each pattern specified is a sequence of one or more strings. Strings can be separated by newline characters or given in separate expression options. A pattern matches an input line if the line contains any of the strings in the sequence. The same functionality is obtained by using Each line is preceded by the block number on which it was found. This is useful in locating disk block numbers by context. Block numbers are calculated by dividing by 512 the number of bytes that have been read from the file and rounding down the result. Only a count of matching lines is printed. Same as a simple expression argument, but useful when the expression begins with a hyphen Multiple options can be used to specify multiple patterns; an input line is selected if it matches any of the specified patterns. The regular expression and or strings list is taken from the pattern_file. Suppress printing of filenames when searching multiple files. Ignore uppercase/lowercase distinctions during comparisons. Only the names of files with matching lines are listed (once), separated by newlines. If standard input is searched, a path name of will be written, in the POSIX locale. In other locales, may be replaced by something more appropriate in those locales. Each line is preceded by its relative line number in the file starting at 1. The line number is reset for each file searched. This option is ignored if or is specified. (Quiet) Do not write anything to the standard output, regardless of matching lines. Exit with zero status upon finding the first matching line. Overrides any options that would produce output. Error messages produced for nonexistent or unreadable files are suppressed. All lines but those matching are printed. Select only those lines containing matches that form whole words. The test is that the matching substring must either be at the beginning of the line, or pre- ceded by a non-word constituent character. Similarly, it must be either at the end of the line or followed by a non-word constituent character. Word-constituent characters are letters, digits, and the underscore. (eXact) Matches are recognized only when the entire input line matches the fixed string or regular expression. The file name is output in all the cases in which output is generated if there are more than one input file, unless the -h option is speci- fied. Care should be taken when using the characters and in expression, because they are also meaningful to the shell. It is safest to enclose the entire expression argument in single quotes EXTERNAL INFLUENCES
Environment Variables determines the locale to use for the locale categories when both and the corresponding environment variable (beginning with do not specify a locale. If is not specified or is set to the empty string, a default of (see lang(5)) is used. determines the locale to use to override any values for locale categories specified by the settings of or any environment variables begin- ning with determines the collating sequence used in evaluating regular expressions. determines the interpretation of text as single byte and/or multi-byte characters, the classification of characters as letters, the case information for the option, and the characters matched by character class expressions in regular expressions. determines the language in which messages are displayed. If any internationalization variable contains an invalid setting, the commands behave as if all internationalization variables are set to See environ(5). International Code Set Support Single-byte and multi-byte character code sets are supported. RETURN VALUE
Upon completion, returns one of the following values: One or more matches found. No match found. Syntax error or inaccessible file (even if matches were found). EXAMPLES
In the POSIX shell (sh(1)) the following example searches two files, finding all lines containing occurrences of any of four strings: Note that the single quotes are necessary to tell when the strings have ended and the file names have begun. For the C shell (see csh(1)) the following command can be used: To search a file named containing the following entries: the command: prints: To search a file for lines that contain either a or use either of the following commands: Search all files in the current directory for the string Search all files in the current directory subtree for the string and ensure that no error occurs due to file name expansion exceeding sys- tem argument list limits: The previous example does not print the name of files where string appears. To force to print file names, add a second argument to the command portion of the command line: In this form, the first file name is that produced by and the second file name is the null file. WARNINGS
(XPG4 only.) If the option is specified, the exit status will be zero if an input line is selected, even if an error was detected. Other- wise, default actions will be performed. If the option is specified with non-word constituent characters, then the output is unexpected. SEE ALSO
sed(1), sh(1), regcomp(3C), environ(5), lang(5), regexp(5). STANDARDS CONFORMANCE
grep(1)
All times are GMT -4. The time now is 02:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy