Create a file with input values required


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Create a file with input values required
# 1  
Old 08-29-2013
Create a file with input values required

Hi Guys

Please can you help me to create a file using the following inputs
2351 first input
2339 second input
all this rows need to have the value 0 in front
2338 third input
2333 fourth input
all this rows need to have the value 1 in front
count all the rows in the file and insert the value in a new line in the first line of the file should be 19 for this example.

There is a blank space at the beginning and at the end of each line, and also need to be create a line at the end of the file without any blank space

Desired output file

Code:
 19
 2351          0 
 2350          0 
 2349          0 
 2348          0 
 2347          0 
 2346          0 
 2345          0 
 2344          0 
 2343          0 
 2342          0 
 2341          0 
 2340          0 
 2339          0 
 2338          1 
 2337          1 
 2336          1 
 2335          1 
 2334          1 
 2333          1

Your help is appreciated Smilie
# 2  
Old 08-29-2013
Code:
awk -vf1=outfile '/2351/,/2339/ {$2=0} /2338/,/2333/ {$2=1} {a=a$0"\n"} END{print NR>f1; print a>>f1}' infile

This User Gave Thanks to krishmaths For This Post:
# 3  
Old 08-29-2013
Hi Krishmaths
I run the command but it doesnot work
# 4  
Old 08-29-2013
Hi jiam,

1. Did you receive any error message?
2. If you had got back to the prompt after the command executed then check if file outfile is created in current directory
This User Gave Thanks to krishmaths For This Post:
# 5  
Old 08-29-2013
Hi Khishmaths

Using your code I did the following script and I got the output file as desired.

Code:
rm -f *swseq*

      printf "Please enter the swath numbers in order of recording.\n"
      printf "\n"
      printf "First swath for shipmenth: "
             set fswship = ($<)
      printf "\n"
      printf "Last swath for shipmenth): "
             set lswship   = ($<)

ls -l *sps* | awk '{x=substr($9,3,4);print x}' | uniq | sort -$BDR > list.tmp

set fsw = $FIRST_SWATH
set lsw = $lswship

awk -vf1=list1.tmp '/'$fsw'/,/'$lsw'/ {$2="         0 "} /'$fswship'/,/'$lswship'/ {$2="         1 "} {a=a$0"\n"} END{print NR>f1; print a>>f1}' list.tmp

awk 'NF > 0' list1.tmp > list2.tmp

cat list2.tmp | awk '{print " " $0}' > swseq.tmp

      printf "\n"

unix2dos swseq.tmp

# 6  
Old 08-29-2013
How about
Code:
set 2351 2339 2338 2333
echo $(($1-$2+$3-$4+2))
printf "%s\t0\n" $(seq $1 -1 $2)
printf "%s\t1\n" $(seq $3 -1 $4)
19
2351    0
2350    0
2349    0
2348    0
2347    0
2346    0
2345    0
2344    0
2343    0
2342    0
2341    0
2340    0
2339    0
2338    1
2337    1
2336    1
2335    1
2334    1
2333    1

If you copy that to a shell script, you can call it with your numbers as parameters 1 - 4.
This User Gave Thanks to RudiC For This Post:
# 7  
Old 08-30-2013
Thanks RudiC
It works fine.. great job

---------- Post updated 08-30-13 at 05:13 AM ---------- Previous update was 08-29-13 at 02:07 PM ----------

RudiC

Here my script ,, thanks for your helpSmilieSmilieSmilie

Code:
      printf "Please enter the swath numbers in order of recording.\n"
      printf "\n"
             read -p "Last swath for the previous shipment: " lastsw1
      printf "\n"
             read -p "Last swath for actual shipmenth : " lastsw2


fsw=2351
lsw1=$lastsw1
fsw2=`expr $lastsw1 - 1`
lsw2=$lastsw2


set $fsw $lsw1 $fsw2 $lsw2

echo $(($1-$2+$3-$4+2)) > tmx1
printf "%s          0 \n" $(seq $1 -1 $2) > tmx2
printf "%s          1 \n" $(seq $3 -1 $4) > tmx3

cat tmx1 tmx2 tmx3 > tmx4

cat tmx4 | awk '{print " " $0}' > tmx5

mv tmx5 swseq.tmp

unix2dos -q swseq.tmp

rm -f *tmx*

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check if 2 input values exists in a file

I have a file number.txt.I need to get 2 inputs from the terminal like a=100 and b=200.If a and b are there in the file,then check if a < b,print "less".If a is not there in the file,print "a is missing" or if b is not there in the file,print "b is missing". number.txt: 100 200 300 (2 Replies)
Discussion started by: aneeta13
2 Replies

2. Shell Programming and Scripting

Bash to search file based off user input then create new file

In the below bash a file is downloaded when the program is opened and then that file is searched based on user input and the result is written to a new file. For example, the bash is opened and the download.txt is downloaded, the user then enters the id (NA04520). The id is used to search... (5 Replies)
Discussion started by: cmccabe
5 Replies

3. Shell Programming and Scripting

Replace two values in a file with input from two different files

Hi, I was having the following issue cat input hello1, my name is unix.com. I am awesome. Hope you know this, hello2! cat hello1.txt Hi Friends Hi Folks Hi Well-Wishers cat hello2.txt Honey Sweety Darling Required Output (8 Replies)
Discussion started by: jacobs.smith
8 Replies

4. Shell Programming and Scripting

Create different files from input file.

I have file A.txt File A 1,Hi,234 2,Hello,345 1,Kal,980, 9,KJ,098 2,de,098 .. ... I have more then 600 lines... I want separate the files as per 150 line. First 150 lines ----File A1.xtx Second 150 lines ---File A2.txt Third 150 lines----File A3.txt. ... (4 Replies)
Discussion started by: asavaliya
4 Replies

5. Shell Programming and Scripting

How to generate a csv files by separating the values from the input file based on position?

Hi All, I need help for doing the following. I have a input file like: aaaaaaaaaabbbbbbbbbbbbbbbbbbbb cccbbbbbaaaaaadddddaaaabbbbbbb now I am trying to generate a output csv file where i will have for e.g. 0-3 chars of each line as the first column in the csv, 4-10 chars of the line as... (3 Replies)
Discussion started by: babom
3 Replies

6. Shell Programming and Scripting

Print required values at end of the file by using AWK

I am looking help in awk, quick overview. we will get feed from external system . The input file looks like below. Detail Id Info Id Order Id STATUS Status Date FileDetail 99127942 819718 CMOG223481502 PR 04-17-2011 06:01:34PM... (7 Replies)
Discussion started by: dvrbabu
7 Replies

7. Shell Programming and Scripting

Create Multiple files by reading a input file and changing the contents

Being new to this area .I have been assigned a task which i am unable to do . Can any one please help me . Hi I have requirement where i have input file XYZ_111_999_YYYYMMDD_1.TXT and with header and series of Numbers and Footer. I want to create a mutiple output files with each file having a... (2 Replies)
Discussion started by: bhargavkr
2 Replies

8. UNIX for Dummies Questions & Answers

Create file with column values

Hi, I have a data file looks like the following ID STARTDATE ENDDATE 101 20090520 20090521 102 20090521 20090522 103 20090522 20090523 104 20090523 20090524 105 20090524 20090525 106 20090525 20090526 107 ... (3 Replies)
Discussion started by: naveen.kuppili
3 Replies

9. UNIX for Dummies Questions & Answers

create an input file

I am using a large unix server at my college. I have remote access to it on my laptop. I have installed a program on the large unix server, and want to write to the program. How do I alter parameters to read input and write output somewhere else?. I would like to read input and write output to my... (2 Replies)
Discussion started by: stonna
2 Replies

10. Shell Programming and Scripting

How to create a directory structure with getting input from a file.

Hi How to create a directory structure with getting input from a file. I have file in that following lines are written. ./activemq-4.1.2/activemq-core-4.1.2.jar ./activemq-4.1.2/backport-util-concurrent-2.1.jar ./camel-1.4.0/apache-camel-1.4.0.jar ./camel-1.4.0/lib/activation-1.1.jar... (12 Replies)
Discussion started by: itsjoy2u
12 Replies
Login or Register to Ask a Question