AWK a variable Ouptut to a new variable and using the new variable with the old one
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
AWK a variable Ouptut to a new variable and using the new variable with the old one
Dear All,
I am trying to change a filename viz; ABC.txt, to ABC_utf8.txt
Once I get the _utf8* named file.. my directory should have two files, ABC.txt and ABC_utf8.txt
Thus later I would try and use "iconv" on ABC.TXT and change the char-set and generate "ABC_utf8.txt"
But all the time, my both variable store same value "ABC.txt"
I don't think you need to use awk for this. You can do the whole thing in one line with bash's parameter substitution. Assuming all input files have a ".txt" extension:
I don't think you need to use awk for this. You can do the whole thing in one line with bash's parameter substitution. Assuming all input files have a ".txt" extension:
Glad to help. It's usually more productive to state the results you want, and let people give you possible solutions, than to restrict yourself to using a specific tool from the outset.
By the way, your original problem seems to be 1) an unwanted space between the "=" and the "$", and 2) some unnecessary quote marks. This works for me:
But there are lighter tools you can use than awk, even if you don't go with parameter substitution (i.e. you're using a shell other than bash). Since it's just a simple text string substitution, how about sed?
Code:
FILENAME1=$(echo $FILENAME | sed "s/.txt/_utf8.txt/")
I am actually an Oracle DBA, trying my hand on some of the shell scripting, to ensure that some of the manual tasks my developers do, are removed from their hectic responsibilities.
They generate a file (a flat file of encoding type ANSI) through Oracle (which is based on a HP Unix box) on a NAS Server running on windows, so I pick it from there, load it onto Linux convert the char-set to UTF8 and push it back to the NAS, so that they can have it as UTF8 as desired.
Your subsitution command did work for me, and I did edit the same in my code,
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.