Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Using sed to replace a range of number Post 302920349 by Don Cragun on Thursday 9th of October 2014 02:43:50 AM
Old 10-09-2014
Quote:
Originally Posted by jimmyf
Scrutinizer, your logic works nicely but is there a way to also echo the original numeric value?

---------- Post updated at 01:34 AM ---------- Previous update was at 01:27 AM ----------

Thank you very much guys.
You lost me. No numbers are being changed. Why do you want to echo the original number and echo the original number plus the word range?

If you want to use sed instead of awk for this, try:
Code:
sed -e 's/^ *[1-9] *$/& range/' -e 's/^ *1[0-9] *$/& range/' -e 's/^ *2[0-5] *$/& range/' file

Note that using:
Code:
sed 's/^ *[1-9][0-5]\{0,1\} /&range/' file

will not match any line that does not have a trailing space, and, for lines that do have a trailing space:
  1. will not match lines with the values 16 through 19 (which are in range),
  2. will match lines with the values 30 through 35 (which are not in range),
  3. will match lines with the values 40 through 45 (which are not in range),
  4. will match lines with the values 50 through 55 (which are not in range),
  5. will match lines with the values 60 through 65 (which are not in range),
  6. will match lines with the values 70 through 75 (which are not in range),
  7. will match lines with the values 80 through 85 (which are not in range), and
  8. will match lines with the values 90 through 95 (which are not in range).
These 3 Users Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sed command to find, manipulate and replace a number

Hi, Im very new to the world of sed so I'm really not even sure if this is possible. What i need to do is read from a flat file and every time i see this line: VAL=123,456 I need to change 456 to 457 for every occurence of this line in the file. The numbers 123 and 456 are different for... (6 Replies)
Discussion started by: LT_2008
6 Replies

2. Shell Programming and Scripting

How to replace a range of text with sed or awk?

Howdy! I'm trying to automate editing of a configuration file (custom.conf for GDM). I need to find every line between a line that starts with "" and the next line that starts with "", I want to preserve that line, but then delete all the lines in that configuration section and then insert... (3 Replies)
Discussion started by: TXTad
3 Replies

3. UNIX for Dummies Questions & Answers

Sed to replace second number in a random string

I need a sed line that will take STDM111 and change it to STDM161 the STDM will always be constant but the 3 numbers after will be random, I just need it to always replace the middle number with 6 regardless of what the numbers are. (8 Replies)
Discussion started by: glev2005
8 Replies

4. Shell Programming and Scripting

Using SED to replace a random number?

Hi all, I need to run a number of scripts which have a certain phrase on them so I have identified these by; grep -l 100 *script | sort -u Normally I could just run something along the lines of; for i in `grep -l 100 *script | sort -u`; do ./${i}; done However before I run each of... (0 Replies)
Discussion started by: JayC89
0 Replies

5. Shell Programming and Scripting

Replace a null from grep to a number 0 using sed

Hi I have a file which contains count for a code. Code is first field and count is second field. I am trying to search the code and get correspond count. File look like this. temp.out A 10 B 20 I am searching for C , if C is not there I will have get value 0. I have... (5 Replies)
Discussion started by: dgmm
5 Replies

6. Shell Programming and Scripting

Replace x Number of String Occurrence with Sed

Ok, So I have a huge file that has over 12000 lines in it. in this file, there are 589 occurrences of the string "use five-minute-interval" spread in various areas in the file. How can i replace the the last 250 of the occurrences of "use five-minute-interval" with "use... (10 Replies)
Discussion started by: SkySmart
10 Replies

7. Shell Programming and Scripting

Replace a pattern in a file with a generated number using sed or awk

my file has thousands of line but let me show what i want to achieve... here is one line from that file cat fileName.txt (2,'','user3002,user3003','USER_DATA_SINGLE',1,0,0,'BACKUP',2,NULL,0,450,NULL,NULL,'','2011-05-10... (13 Replies)
Discussion started by: vivek d r
13 Replies

8. Shell Programming and Scripting

Sed print range of lines between line number and pattern

Hi, I have a file as below This is the line one This is the line two <\XMLTAG> This is the line three This is the line four <\XMLTAG> Output of the SED command need to be as below. This is the line one This is the line two <\XMLTAG> Please do the need to needful to... (4 Replies)
Discussion started by: RMN
4 Replies

9. Shell Programming and Scripting

sed to replace the matching pattern with equal number of spaces

Hi I have written a shell script which used sed code below sed -i 's/'"$Pattern"'/ /g' $FileName I want to count the length of Pattern and replace it with equal number of spaces in the FileName. I have used $(#pattern) to get the length but could not understand how to replace... (8 Replies)
Discussion started by: rakeshkumar
8 Replies

10. Shell Programming and Scripting

sed replace range of characters in each line

Hi, I'm trying to replace a range of characters by their position in each line by spaces. I need to replace characters 95 to 145 by spaces in each line. i tried below but it doesn't work sed -r "s/^(.{94})(.{51})/\ /" inputfile.txt > outputfile.txt can someone please help me... (3 Replies)
Discussion started by: Kevin Tivoli
3 Replies
All times are GMT -4. The time now is 11:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy