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 302561538 by right_coaster on Tuesday 4th of October 2011 11:32:01 AM
Old 10-04-2011
Need an awk / sed / or perl one-liner to remove last 4 characters with non-unique pattern.

Hi, I'm writing a ksh script and trying to use an awk / sed / or perl one-liner to remove the last 4 characters of a line in a file if it begins with a period.

Here is the contents of the file... the column in which I want to remove the last 4 characters is the last column. ($6 in awk). I've tried a few commands but I'm totally stumped. Thanks for any assistance.

Code:
 
QUX         | LIBMEM.SYS.OA      | 20110920 110704.951
SA          | LIBMEM.SYS.OA      | 20110920 110706
SD          | LIBMEM.SYS.OA      | 20110920 110708
SP          | LIBMEM.SYS.OA      | 20110920 110711.503
SR          | LIBMEM.SYS.OA      | 20110920 110713
SYSTEM      | LIBMEM.SYS.OA      | 20110920 110714.413
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.102
WS          | LIBMEM.SYS.OA      | 20110923 084845.744
AD          | LIBMEM.SYS.OA      | 20110920 112837
AQ          | LIBMEM.SYS.OA      | 20110920 112839.880
DD          | LIBMEM.SYS.OA      | 20110920 112840
DP          | LIBMEM.SYS.OA      | 20110920 112842

Desired file contents:
Code:
 
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

Thanks!
 

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
IBDM-TOPO-FILE(1)					       IB DATA MODEL PACKAGE						 IBDM-TOPO-FILE(1)

NAME
IBDM Topology File The topology file describes the IB connectivity and systems included in the network. It serves two purposes: 1. Support for arbitrary system names to be later used in every report that IBDM generates. 2. Connectivity verification: The specified network topology is verified against the discovered one. Mismatch errors resulting from missing cables and/or wrong connections are reported by IBADM. The topology file is composed "system" sections. Each such section describes the connectivity of one system to other systems in the net- work. The first line of each section is a declaration of the system composed of a system-type, its system-name section, and optional con- figuration details. The lines to follow until the next empty line describe the connections between this system ports to the other systems. The following is a formal definition of a system section syntax. An example is listed afterwards. SYSTEM-TYPE SYSTEM-NAME [CFG: <b1>=<modifier>, [<b2>=<modifier>]...] LOCAL-PORT-PANEL-NAME -> REM-SYS-TYPE REM-SYS-NAME REM-PORT-PANEL-NAME LOCAL-PORT-PANEL-NAME -> REM-SYS-TYPE REM-SYS-NAME REM-PORT-PANEL-NAME LOCAL-PORT-PANEL-NAME -> REM-SYS-TYPE REM-SYS-NAME REM-PORT-PANEL-NAME . . . SYSTEM-TYPE SYSTEM-NAME [CFG: <b1>=<modifier>, [<b2>=<modifier>]...] LOCAL-PORT-PANEL-NAME -> REM-SYS-TYPE REM-SYS-NAME REM-PORT-PANEL-NAME LOCAL-PORT-PANEL-NAME -> REM-SYS-TYPE REM-SYS-NAME REM-PORT-PANEL-NAME . . . . . . Where: SYSTEM-TYPE and REM-SYS-TYPE Any system that has a corresponding IBNL definition. See man ibdm-ibnl-file SYSTEM-NAME The name of the system described in this topology file section. LOCAL-PORT-PANEL-NAME The name of the local system port. The numbers printed on the front panel are used together with Ln for Leaf no. N or Sn for Spine no. N. REM-SYS-NAME The name of the system connected to the local port. REM-PORT-PANEL-NAME A name of the remote system port. We use the numbers as printed on the front panel and Ln for Leaf number N or Sn for Spine number N. EXAMPLE
The following is a topology file for a simple cluster with one 24 port switch and two HCAs. The firts HCA named H-1 and connect to the fab- ric with its two ports. The second HCA named H-2. The switch is of type MTS2400 and is named S-1 MTS2400 S-1 P1 -> MT23108 H-1 P1 P2 -> MT23108 H-1 P2 P24 -> MT23108 H-2 P1 OPTIONAL CFG SECTION
This section in the system declaration line describes the special customization of each board of the system. That is the CFG string is a set of comma-separated sub-fields. Each sub-field describes some special configuration of a corresponding sys- tem board. The actual semantics of the specific board modifiers is defined by the IBNL of the specific system. EXAMPLE
The following is an example of a definition-line in a topology file of the MTS9600 switch system. This switch system can have up to eight leafs and four spines. This example of the MTS9600 lacks (R) leafs no.6,7 and 8, and lacks spines no. 3 and 4. MTS9600 PartialGz1 CFG: leaf3=R,leaf5=R,leaf7=R,spine1=R AUTHOR
Eitan Zahavi, Mellanox Technologies LTD, eitan@mellanox.co.il IBDM 1.0 2008-06-16 IBDM-TOPO-FILE(1)
All times are GMT -4. The time now is 10:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy