I am facing a problem in replacing the file contents by iterating through the list.
My present code:
Code:
and my
country code file contains some county code on line basis, seperated with commas.
Here after executing the script, only last country code is replacing with its country name. And if I change > (overwriting) to >> (appending) then same contents, multiple times with changes are appending to output file. I request you to suggest a solution for this.
And my second concern is that I have to append the name of the file at the end of each line, which I hav done using the commented line. Request you to suggest to perform both actions at a stretch.
First off, it would have been nice to show at least some sample lines from country_code.txt, which you read in. It is hard to predict what your code is doing when one is missing the input data it works on.
Second, you should write your code in an understandable way. You concatenate keywords (which isn't allowed at all), have several commands in one line without separating them by semicolons (which isn't allowed either) and don't indent properly (which is allowed, but makes it overly hard to read):
Third you should indeed use ">>" instead of ">", otherwise your output file will be overwritten with every pass of the loop. Anyhow, a lot of your loop is absolutely superfluous. The variable "aline" is not needed at all. Additionally you are writing to the input file "sed" reads from (for which you define a variable but never use it), which is not forbidden, but will not give the results you want:
I still don't get the meaning of the second sed-statement, because several passes of the loop will add "| testb_1.txt" to the end of each line.
Just in case you have a list of country-codes and what to replace them by the countries names, your code won't do it anyhow:
I won't expand on the recurring theme of replacing the "echo ... | cut ..." with simple shell variable expansions, i suppose this is enough for one session to devour.
Hi,
I am trying to do something similar to the for loop example from KSH For Loop Array: Iterate Through Array Values
$: cat y.ksh
#!/bin/ksh
# set array called nameservers
set -A nameservers 192.168.1.1 192.168.1.5 202.54.1.5
# print all name servers
for i in ${nameservers}
do
... (3 Replies)
I need to run the same awk function over an entire directly of files.
This is the awk:
awk '{$(NF+1)=1}1'
Is there a way that I can run this command once over all of the files, along the lines of:
awk '{$(NF+1)=1}1' *
so that I do not have to run this several times?
My main concern is... (2 Replies)
I am trying to look through one of my directories to remove certain files. I am pretty new to Unix and bash so I just need a little help in starting this. I know I would have to write two loops one to iterate the directories and one to iterate the files. How would I write the loops? (3 Replies)
Hi,
I've recently started using Awk commands as i need it to pull information out of a file and give me the mean value of a series of numbers. Here is the code i run on my Infile and it works just fine.
awk '{if ($1 == "Mam189") print $0}' Infile | awk '{if ($1 != $2) print $0}' | awk... (5 Replies)
Hello, I am working on a coding project for a class and to test the program I have created, I have come up with 100 different test cases. The program takes four text files as input, so each of the test cases is contained in a folder with four files.
I have a folder called 'tests', within which... (1 Reply)
Whilst creating the function readjust_descr I have stumble across what may be a problem or
something that might just work. I was hoping someone could look at the code below and tell me
if readjust_descr will clear all null pointers from the structure descr_list.
struct descr descr_list =... (6 Replies)
Hey everyone.
Is it possible to use two arrays in a loop?
Basically what I am trying to do is iterate through the elements in an array, and, based on a condition, use the current position in the array to point to that index in the array. Here's the loop structure I'm looking for:
... (1 Reply)
hi all,
i am writing a ksh script, i am logging into an oracle db via sqlplus and running a select statement but i dont know how i can store the results from the sql so i can iterate over it and do more operations over it. I dont want to write a stored procedure with a cursor since i need to... (2 Replies)
I have a Bash script on Cygwin that tries to iterate through the directory entries in PATH. I need to convert the PATH value to a form that I can iterate through with "for var in $list; do".
For instance, an excerpt from my PATH value is this:
:/c/Program Files/Windows Imaging/:/c/Program... (2 Replies)
i've reworked some code from an earlier post, and it isn't working as expected
i've simplified it to try and find the problem. i spent hours trying to figure out what is wrong, eventually thinking there was a bug in perl or a problem with my computer. but, i've tried it on 3 machines with the... (5 Replies)