Sponsored Content
Full Discussion: Remove prefix using awk
Top Forums Shell Programming and Scripting Remove prefix using awk Post 302321626 by pinnacle on Monday 1st of June 2009 06:21:15 PM
Old 06-01-2009
Remove prefix using awk

Remove prefix using awk

File:
Quote:
xyz.amp|x|a|t
xyz.tmpx|a|t
aic.klmx|a|t
jil.djn|a|t
mno.djn|j|k
dij.iuy|a|t
Code:
 nawk -F"|" '{if ($1 ~ /^xyz./) print; else { gsub(.*\..*, \..*, $1) ;print }}' file

Error:
Quote:
nawk: syntax error at source line 1
context is
{if ($1 ~ /^xyz./) print; else { >>> gsub(. <<< *\..*, \..*, $1) ;print}}

ouput required:
Quote:
xyz.amp|x|a|t
xyz.tmpx|a|t
klmx|a|t
djn|a|t
djn|j|k
iuy|a|t
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

remove filename prefix

I've got a bunch of files called oldabc, olddef etc. i want to copy these to be abc, def.... I can do this with file extensions....but can get the logic to work for prefixes. All the files I am interested in have a prefix of 'old'. This loop is no good for me....it looks at the content... (2 Replies)
Discussion started by: peter.herlihy
2 Replies

2. Shell Programming and Scripting

Remove prefix from filenames

I'm trying to put together a shell script that will append specific prefixes based on the content of filenames. I think I have this part down. However, I want to append before that part a process that will remove the current prefix before it renames the files with the new prefix. For example,... (6 Replies)
Discussion started by: HLee1981
6 Replies

3. Shell Programming and Scripting

Need awk script to add a prefix to each line in file

Hello , I have file with below content : '165567885', '165568443', '165568805', I need an awk script that would add a prefix zero after first ' . Like '0165567885', '0165568443', '0165568805', Please help. Thanks in advance. (5 Replies)
Discussion started by: rmv
5 Replies

4. Shell Programming and Scripting

Remove prefix per line in file

Hi, I'm using a .ksh script to split one file into multible files by checking for the prefix per line. It works perfekt (thanks again for anyone involved in helping me with that ;)), but I want to remove the prefix per line too. Means only the line information itself should remain in the... (7 Replies)
Discussion started by: spidermike
7 Replies

5. Linux

Adding a prefix to a column using awk/sed commands

Hello, I am a newbie to linux and struggling to find a better way to append a column in a text file. Here is the file i want to modify: It has 8 columns (and thousands of rows). I want to append the first column by adding "chr" infront of the numbers. Some rows have a string in the first... (4 Replies)
Discussion started by: bjorngill
4 Replies

6. Shell Programming and Scripting

AWK adding prefix/suffix to list of strings

75 103 131 133 138 183 197 221 232 234 248 256 286 342 368 389 463 499 524 538 (5 Replies)
Discussion started by: chrisjorg
5 Replies

7. Shell Programming and Scripting

awk to remove last two -*-*

fq-bar-something-1.0-r1.src.rpm ----> fq-bar-something fq-bar-xx-r1-rel.src.rpm ---------> fq-bar-xx fq-bar-ff-ver-11-rel.src.rpm -------> fq-bar-ff-ver any help? (5 Replies)
Discussion started by: yanglei_fage
5 Replies

8. Shell Programming and Scripting

Extract Uniq prefix from a start and end prefix

Dear All, assume i have a file with content: <Start>6000</Start> <Stop>7599</Stop> the output is: 6000 7000 7100 7200 7300 7400 7599 how should we use any awk, sed, perl can do this task, means to extract the uniq prefixes from the start and stop prefix. Thanks Jimmy (3 Replies)
Discussion started by: jimmy_y
3 Replies

9. Shell Programming and Scripting

Need to add prefix using sed or awk from cat the file

I need the use sed or AWK using cat the file Node1 TDEV RW 1035788 TDEV RW 1035788 Server1 TDEV RW 69053 Server2 TDEV RW 69053 TDEV RW 103579 Server3 TDEV RW 69053 server4 RDF1+TDEV RW 69053 RDF1+TDEV RW 517894 RDF1+TDEV RW 621473 server6 TDEV RW 34526 TDEV RW 34526 (22 Replies)
Discussion started by: ranjancom2000
22 Replies

10. Shell Programming and Scripting

awk move select fields to match file prefix in two directories

In the awk below I am trying to use the file1 as a match to file2. In file2 the contents of $5,&6,and $7 (always tab-delimited) and are copied to the output under the header Quality metrics. The below executes but the output is empty. I have added comments to help and show my thinking. Thank you... (0 Replies)
Discussion started by: cmccabe
0 Replies
pnmcrop(1)                                                    General Commands Manual                                                   pnmcrop(1)

NAME
pnmcrop - crop a portable anymap SYNOPSIS
pnmcrop [-white|-black|-sides] [-left] [-right] [-top] [-bottom] [pnmfile] All options may be abbreviated to their shortest unique prefix or specified with double hyphens. DESCRIPTION
Reads a PBM, PGM, or PPM image as input. Removes borders that are the background color, and produces the same type of image as output. If you don't specify otherwise, pnmcrop assumes the background color is whatever color the top left and right corners of the image are and if they are different colors, something midway between them. You can specify that the background is white or black with the -white and -black options or make pnmcrop base its guess on all four corners instead of just two with -sides. By default, pnmcrop chops off any stripe of background color it finds, on all four sides. You can tell pnmcrop to remove only specific borders with the -left, -right, -top, and -bottom options. If you want to chop a specific amount off the side of an image, use pnmcut. If you want to add different borders after removing the existing ones, use pnmcat or pnmcomp. OPTIONS
-white Take white to be the background color. pnmcrop removes borders which are white. -black Take black to be the background color. pnmcrop removes borders which are black. -sides Determine the background color from the colors of the four corners of the input image. pnmcrop removes borders which are of the background color. If at least three of the four corners are the same color, pnmcrop takes that as the background color. If not, pnmcrop looks for two corners of the same color in the following order, taking the first found as the background color: top, left, right, bottom. If all four corners are different colors, pnmcrop assumes an average of the four colors as the background color. The -sides option slows pnmcrop down, as it reads the entire image to determine the background color in addition to the up to three times that it would read it without -sides. -left Remove any left border. -right Remove any right border. -top Remove any top border. -bottom Remove any bottom border. -verbose Print on Standard Error information about the processing, including exactly how much is being cropped off of which sides. SEE ALSO
pnmcut(1), pnmfile(1), pnm(5) AUTHOR
Copyright (C) 1989 by Jef Poskanzer. 18 March 2001 pnmcrop(1)
All times are GMT -4. The time now is 12:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy