Sponsored Content
Top Forums Shell Programming and Scripting Need an awk / sed / or perl one-liner to remove last 4 characters with non-unique pattern. Post 302561672 by itkamaraj on Tuesday 4th of October 2011 10:53:56 PM
Old 10-04-2011
Code:
 
nawk -F\| 'BEGIN{OFS="|"}{if($NF~/\./)$NF=substr($NF,1,index($NF,".")-1); print}' test                                                           
QUX         | LIBMEM.SYS.OA      | 20110920 110704
SA          | LIBMEM.SYS.OA      | 20110920 110706
SD          | LIBMEM.SYS.OA      | 20110920 110708
SP          | LIBMEM.SYS.OA      | 20110920 110711
SR          | LIBMEM.SYS.OA      | 20110920 110713
SYSTEM      | LIBMEM.SYS.OA      | 20110920 110714
UB          | LIBMEM.SYS.OA      | 20110920 110716
VDRDAILY    | LIBMEM.SYS.OA      | 20110920 110720
VDRWKLY     | LIBMEM.SYS.OA      | 20110920 110831
VP          | LIBMEM.SYS.OA      | 20110920 110834
WC          | LIBMEM.SYS.OA      | 20110922 131601
WS          | LIBMEM.SYS.OA      | 20110923 084845
AD          | LIBMEM.SYS.OA      | 20110920 112837
AQ          | LIBMEM.SYS.OA      | 20110920 112839
DD          | LIBMEM.SYS.OA      | 20110920 112840
DP          | LIBMEM.SYS.OA      | 20110920 112842

---------- Post updated at 08:23 AM ---------- Previous update was at 08:19 AM ----------

Code:
$ perl -lane '$_=~s/[.][0-9]*$//; print $_' test
QUX         | LIBMEM.SYS.OA      | 20110920 110704
SA          | LIBMEM.SYS.OA      | 20110920 110706
SD          | LIBMEM.SYS.OA      | 20110920 110708
SP          | LIBMEM.SYS.OA      | 20110920 110711
SR          | LIBMEM.SYS.OA      | 20110920 110713
SYSTEM      | LIBMEM.SYS.OA      | 20110920 110714
UB          | LIBMEM.SYS.OA      | 20110920 110716
VDRDAILY    | LIBMEM.SYS.OA      | 20110920 110720
VDRWKLY     | LIBMEM.SYS.OA      | 20110920 110831
VP          | LIBMEM.SYS.OA      | 20110920 110834
WC          | LIBMEM.SYS.OA      | 20110922 131601
WS          | LIBMEM.SYS.OA      | 20110923 084845
AD          | LIBMEM.SYS.OA      | 20110920 112837
AQ          | LIBMEM.SYS.OA      | 20110920 112839
DD          | LIBMEM.SYS.OA      | 20110920 112840
DP          | LIBMEM.SYS.OA      | 20110920 112842

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove spaces using awk,sed,perl?

Input: 3456 565 656 878 235 8 4 8787 3 7 35 878 Expected output: 3456 565 656 878 235 8 4 8787 3 7 35 878 How can i do this with awk,sed and perl? (10 Replies)
Discussion started by: cola
10 Replies

2. Shell Programming and Scripting

Deleting characters with sed,perl,awk

Input: :: gstreamer :: xine-lib :: xine-lib-extras Output should be: gstreamer xine-lib xine-lib-extras How can it be done with sed or perl? (12 Replies)
Discussion started by: cola
12 Replies

3. Shell Programming and Scripting

Search & Replace regex Perl one liner to AWK one liner

Thanks for giving your time and effort to answer questions and helping newbies like me understand awk. I have a huge file, millions of lines, so perl takes quite a bit of time, I'd like to convert these perl one liners to awk. Basically I'd like all lines with ISA sandwiched between... (9 Replies)
Discussion started by: verge
9 Replies

4. Shell Programming and Scripting

Sed or awk : pattern selection based on special characters

Hello All, I am here again scratching my head on pattern selection with special characters. I have a large file having around 200 entries and i have to select a single line based on a pattern. I am able to do that: Code: cat mytest.txt | awk -F: '/myregex/ { print $2}' ... (6 Replies)
Discussion started by: usha rao
6 Replies

5. UNIX for Dummies Questions & Answers

One liner pattern search with awk/sed/grep

I have an array containing bunch of characters. I have to check this array for specific character and if "Not Found than" use a goto statement to go to USAGE set options = (A B C D E F) @ i = 0 while ($i <= ${#options}) if ($options != "F" || $options != "D") then goto USAGE endif @... (1 Reply)
Discussion started by: dixits
1 Replies

6. Shell Programming and Scripting

Perl: Pattern to remove words with less than 2 characters.

Hello. I've been thinking about how to go about this. I know I'm close but still does not work. I need to remove any word in that is not at least 2 characters long. I've removed all the non-alphabetic characters already (numbers included). Here's an example: my $string = "This string is a... (4 Replies)
Discussion started by: D2K
4 Replies

7. Shell Programming and Scripting

Awk-sed help : to remove first and last line with pattern match:

awk , sed Experts, I want to remove first and last line after pattern match "vg" : I am trying : # sed '1d;$d' works fine , but where the last line is not having vg entry it is deleting one line of data. - So it should check for the pattern vg if present , then it should delete the line ,... (5 Replies)
Discussion started by: rveri
5 Replies

8. Shell Programming and Scripting

Searching and printing the only pattern using awk,sed or perl

Hi All, i have an output of command vmstat as below : $ vmstat System configuration: lcpu=4 mem=5376MB ent=1.00 kthr memory page faults cpu ----- ----------- ------------------------ ------------ ----------------------- r b avm fre re pi... (10 Replies)
Discussion started by: omkar.jadhav
10 Replies

9. Shell Programming and Scripting

Precede and Append characters using sed/awk based on a pattern

I have an input file which is similar to what I have shown below. Pattern : Data followed by two blank lines followed by data again followed by two blank lines followed by data again etc.. The first three lines after every blank line combination(2 blank lines between data) should be... (2 Replies)
Discussion started by: bikerboy
2 Replies

10. UNIX for Beginners Questions & Answers

awk with sed to combine lines and remove specific odd # pattern from line

In the awk piped to sed below I am trying to format file by removing the odd xxxx_digits and whitespace after, then move the even xxxx_digit to the line above it and add a space between them. There may be multiple lines in file but they are in the same format. The Filename_ID line is the last line... (4 Replies)
Discussion started by: cmccabe
4 Replies
MOPD(8) 						    BSD System Manager's Manual 						   MOPD(8)

NAME
mopd -- Maintenance Operations Protocol (MOP) Loader Daemon SYNOPSIS
mopd [-adf] [-s mopdir] [interface] [...] DESCRIPTION
mopd services DEC Maintenance Operations Protocol (MOP) Load requests on the Ethernet connected to interface or all interfaces if -a option is given. In a load request received by mopd a filename can be given by the client. This is the normal case for terminal servers. If a filename isn't in the client load request mopd must know what image to load. Upon receiving a request, mopd checks if the requested file exists in /tftpboot/mop (unless the -s option is given, see below) the filename is normally uppercase and with an extension of .SYS. If the filename isn't given, the ethernet address of the target is used as filename, e.g. 08002b09f4de.SYS and it might be a soft link to another file. mopd supports two kinds of files. The first type that is check is if the file is in a.out(5) format. If not, a couple of Digital's formats are checked. In normal operation, mopd forks a copy of itself and runs in the background. Anomalies and errors are reported via syslog(3). OPTIONS
-a Listen on all the Ethernets attached to the system. If -a is omitted, an interface must be specified. -d Run in debug mode, with all the output to stdout. The process will run in the foreground. -f Run in the foreground. -s Change the directory to look for files in from /tftpboot/mop to mopdir. FILES
/tftpboot/mop NOTES
mopd automatically appends an upper case .SYS to the filename provided by the client. The typical client sends the requested file name in upper case. SEE ALSO
mopchk(1), mopcopy(1), mopprobe(1), moptrace(1), bpf(4) DECnet Digital Network Architecture Phase IV, Maintenance Operations Functional Specification V3.0.0, AA-X436A-TK. DECnet Digital Network Architecture, Maintenance Operations Protocol Functional Specification V4.0.0, EK-DNA11-FS-001. AUTHORS
Mats O Jansson <moj@stacken.kth.se> BSD
January 23, 2004 BSD
All times are GMT -4. The time now is 09:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy