Echo all numbers in file +/-1


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Echo all numbers in file +/-1
# 1  
Old 03-29-2013
Echo all numbers in file +/-1

I have a plain text file,

Code:
344 392 352 341
405 327 456 765
234 457 874 154
.
.
301 356 789 554

I need a bash script or command (Solaris 10 or Fedora 18) that echos or prints each of the values alongside with the value PLUS ONE, and the value MINUS ONE.

echo $value $value+1 $value-1

Code:
344 345 343 392 393 391 352 353 351 341 342 340
405 406 404 327 328 326 456 457 455 765 766 764
234 235 233 457 458 456 874 875 873 154 155 153
.
.
301 302 300 356 357 355 789 790 788 554 555 553

There are about 100 lines, each value is 100-999
There are only 4 numbers per line.

Last edited by Scrutinizer; 03-30-2013 at 06:00 AM.. Reason: code tags
# 2  
Old 03-29-2013
Code:
awk '{for(i=1;i<=NF;i++){printf ("%d %d %d ",$i,$i+1,$i-1)}print ""}' inuput_file

--ahamed

---------- Post updated at 03:51 PM ---------- Previous update was at 03:42 PM ----------

On Solaris, you may want to use nawk

--ahamed
# 3  
Old 03-30-2013
Or
Code:
awk '{for(i=1;i<=NF;i++) $i=$i" "$i+1" "$i-1}1' numbers.txt

# 4  
Old 03-30-2013
Code:
perl -pe 's/\b(\d+)\b/$1." ".($1+1)." ".($1-1)/eg' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to read specified value from file and echo to the same location to other file.

Hello. I want to to backup some "default:" values from a file do some other job and after restore that "default:" values back. The problem is that the source and destination file has a lot of default: strings in it but with different values... So.. Here is an example: A part of my source... (6 Replies)
Discussion started by: ausdim
6 Replies

2. Shell Programming and Scripting

Adding (as in arithmetic) to numbers in columns in file, and writing new file with new numbers

Hi again. Sorry for all the questions — I've tried to do all this myself but I'm just not good enough yet, and the help I've received so far from bartus11 has been absolutely invaluable. Hopefully this will be the last bit of file manipulation I need to do. I have a file which is formatted as... (4 Replies)
Discussion started by: crunchgargoyle
4 Replies

3. Shell Programming and Scripting

How to read each line from input file, assign variables, and echo to output file?

I've got a file that looks like this (spaces before first entries intentional): 12345650-000005000GL140227 ANNUAL HELC FEE EN 22345650-000005000GL140227 ANNUAL HELC FEE EN 32345650-000005000GL140227 ANNUAL HELC FEE EN I want to read through the file line by line,... (6 Replies)
Discussion started by: Scottie1954
6 Replies

4. Shell Programming and Scripting

Help echo | sed > file

Hello, I am trying to build a very compact script for monitoring FS. I am stuck in a very simple problem (see code comment). Please for your help SERVER_NAME=`uname -n` SCRIPT_DIR=/export/home/scripts/fs_mon4 FLAG_DIR=${SCRIPT_DIR}/flags TEMP_DIR=${SCRIPT_DIR}/tmp FS="\/$"... (1 Reply)
Discussion started by: drbiloukos
1 Replies

5. Shell Programming and Scripting

Script to check for the file existence, if file exists it should echo the no of modified days

Hi, I am looking for a shell script with the following. 1. It should check whether a particular file exists in a location #!/bin/sh if ; then echo "xxx.txt File Exists" else echo "File Not Found" fi 2. If file exists, it should check for the modified date and run a command... (2 Replies)
Discussion started by: karthikeyan_mac
2 Replies

6. Shell Programming and Scripting

the smallest number from 90% of highest numbers from all numbers in file

Hello All, I am having problem to find what is the smallest number from 90% of highest numbers from all numbers in file. I am having file with thousands of lines and hundreds of columns. I am familiar mainly with bash but I am open to whatever suggestion witch will lead to the solutions. If I... (11 Replies)
Discussion started by: Apfik
11 Replies

7. Shell Programming and Scripting

echo ls to a file and then read file and selectively delete

I'm trying to write a script that will do an ls of a location, echo it into a file, and then read that file and selectively delete files/folders, so it would go something like this: cd $CLEAN_LOCN ls >>$TMP_FILE while read LINE do if LINE = $DONTDELETE skip elseif LINE =... (2 Replies)
Discussion started by: MaureenT
2 Replies

8. UNIX for Dummies Questions & Answers

Echo own file name

Hi, I tried to google this but still unable to find the right reseverd word to echo my own file name. Example, I have a script called mytest.sh. Inside mytest.sh, how do I echo its own file name? (2 Replies)
Discussion started by: ngaisteve1
2 Replies

9. Shell Programming and Scripting

read numbers from file and output which numbers belongs to which range

Howdy experts, We have some ranges of number which belongs to particual group as below. GroupNo StartRange EndRange Group0125 935300 935399 Group2006 935400 935476 937430 937459 Group0324 935477 935549 ... (6 Replies)
Discussion started by: thepurple
6 Replies

10. UNIX for Dummies Questions & Answers

echo to a file

I have executeable program: test.exe echo enter a number read number echo a >> file echo b >> file echo $x >> file ./test.exe enter a number 5 cat file I have: a b 5 what is another way to save (3 Replies)
Discussion started by: bobo
3 Replies
Login or Register to Ask a Question