awk string removal


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers awk string removal
# 1  
Old 10-21-2014
awk string removal

Hi,

I am trying to remove a string ".var" using the below command but it's not working as expected, when I execute this in the command prompt using the echo it's working fine , please let me know where I am doing it wrong.

Code:
UYRD=$FILE_$timestamp.csv | awk '{gsub(".var", "");print}' # this is not giving any output

echo /root/src/.var | awk '{gsub(".var", "");print}' #when I tested in command prompt it is working fine

Regards,
Shruthi
# 2  
Old 10-21-2014
Why should it give any output, as there's no input?

EDIT: Try
Code:
UYRD=$(echo $FILE_$timestamp.csv | awk '{gsub(".var", "");print}')

or, you could do it with shell parameter expansion, here: pattern substitution:
Code:
UYRD=${FILE_$timestamp.csv/.var}

This User Gave Thanks to RudiC For This Post:
# 3  
Old 10-21-2014
Thanks for the quick reply.

I tried the first command I am getting the '<' unexpected. And the second command is giving bad substitution error,
# 4  
Old 10-21-2014
Can you show what is stored in this variables
Code:
$FILE_$timestamp.csv

?
This User Gave Thanks to chacko193 For This Post:
# 5  
Old 10-21-2014
timestamp=`date '+%Y%m%d%H%M%S'`
FILE=/root/cdr/src.var.csv
# 6  
Old 10-21-2014
Quote:
Originally Posted by shruthidwh
Thanks for the quick reply.

I tried the first command I am getting the '<' unexpected. And the second command is giving bad substitution error,
Sorry, my fault. Make it
Code:
UYRD=${FILE_/.var}$timestamp.csv

FILE and FILE_ are two different things.

And, use code tags!
This User Gave Thanks to RudiC For This Post:
# 7  
Old 10-21-2014
Try:
Code:
UYRD="$(echo $FILE | awk '{gsub(".var","")}1')_${timestamp}.csv"

This User Gave Thanks to chacko193 For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing string from CSV file by provide removal string from other file

What I need is to remove the text from Location_file.txt from each line matching all entries from Remove_location.txt Location_file.txt FlowPrePaid, h3nmg1cm2,Jamaica_MTAImageFileFlowPrePaid,h0nmg1cm1, Flow_BeatTest,FlowRockTest FlowNewTest,FlowNewTest,h0nmg1cm1 PartiallySubscribed,... (3 Replies)
Discussion started by: ketanraut
3 Replies

2. Shell Programming and Scripting

Removal Extended ASCII using awk

Hi All, I am trying to remove (SELECTIVE - passed as argument) Extended ASCII using Awk based on adhoc basis. Can you please let me know how to do it. I have to implement this using awk only. Thanks & Regads (14 Replies)
Discussion started by: tostay2003
14 Replies

3. Shell Programming and Scripting

String removal from file

Dear all From below mention input file I needed op file as show below. I am using below code but not worked. I/p file BSCBCH1 EXAL-1-4 WO* SMPS MAINS FAIL BSCBCH1 EXAL-1-5 WO* SMPS RECTIFIER FAIL BSCBCH1 EXAL-1-6 WO* SMPS MAJOR ALARM BSCBCH2 EXAL-1-10 WO* ... (5 Replies)
Discussion started by: jaydeep_sadaria
5 Replies

4. Shell Programming and Scripting

awk trailing character removal

Hi, The command - id | awk '{print $1}' - returns the following: uid=9028(luke) What do I need to further that awk so that I only have "luke", I want to set this as a variable. Thanks in advance, Lukas. P.S: I've come up with: USER1=`id | awk F'(' '{print $2}' | awk -F')' '{print... (4 Replies)
Discussion started by: luke222010
4 Replies

5. Shell Programming and Scripting

Undesired removal of white space with awk

Hi, I'm fairly new to scripting and I have a problem that I am having difficulty solving. What I'd like to do is run an awk script to adjust the string in the first field depending on the string in another field. This is best explained with an example: Here is my script: cat... (4 Replies)
Discussion started by: calbrex
4 Replies

6. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

7. Programming

Fast string removal from large text collection

Hi All, I don't want any codes for this problem. Just suggestions: I have a huge collection of text files (around 300,000) which look like this: 1.fil orange apple dskjdsk computer skjks The entire text collection (referenced above) has about 1 billion words. I have created... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

8. Shell Programming and Scripting

any savant ? using AWK/SED to remove newline character between two strings : conditional removal

I'd like to remove (do a pattern or precise replacement - this I can handle in SED using Regex ) ---AFTER THE 1ST Occurrence ( i.e. on the 2nd occurrence - from the 2nd to fourth occurance ) of a specific string : type 1 -- After the 1st occurrence of 1 string1 till the 1st occurrence of... (4 Replies)
Discussion started by: sieger007
4 Replies

9. UNIX for Dummies Questions & Answers

selective removal of blank spaces in string

Hi, I'm a newbie to shell scripting and I have the following problem: I need all spaces between two letters or a letter and a number exchanged for an underscore, but all spaces between a letter and other characters need to remain. Searching forums didn't help... One example for clarity: ... (3 Replies)
Discussion started by: Cpt_Cell
3 Replies

10. Shell Programming and Scripting

Special Character SED/AWK removal

I have a script that produces an output containing '/.ssh'. I am trying to find a way of parsing only this data from a single line, without removing any other special characters contained within the output as a result of the parse. Any help would be appreciated (6 Replies)
Discussion started by: Raggedranger333
6 Replies
Login or Register to Ask a Question