Sponsored Content
Top Forums Shell Programming and Scripting only if column1 equals this print that Post 302187677 by ShawnMilo on Monday 21st of April 2008 04:29:28 PM
Old 04-21-2008
Here's a Python version.

It expects to be run as such: scriptname.py filename.txt

Code:
#!/usr/bin/env python

import sys

file = sys.argv[1]

input = open(file, 'r')

previous = ""

for line in input:

    line = line.rstrip()

    if not previous == "":
        fields = line.split(" ")
        prev = previous.split(" ")
        
        if fields[0] == prev[0]:
            prev.extend(fields[1:])

        print " ".join(prev)

    previous = line

print previous

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

delete a string on column1

Hi I have a file with multiple columns. But there is something weird on column one that is attached to the name. The good thing is that its a consistent pattern so there should be a way to remove it. So the first column looks something like this: name_345.4ml date_3456.4ml year_12.4ml... (3 Replies)
Discussion started by: kylle345
3 Replies

2. Shell Programming and Scripting

Getting rip of multiple rows based on column1

Hi, I want to get rid of multiple rows (duplicate, triplicate etc..) for only column 1. e.g. iu 2 iu 1 iu 3 k 4 jk 3 nm 4 nm 2 output k 4 jk 3 thanks (7 Replies)
Discussion started by: phil_heath
7 Replies

3. Shell Programming and Scripting

How TO: if [ Not Equals ] - Solaris 8

Hi, I have the following script which runs well :- ls -l /etc/*.txt > /dev/null 2>&1 if ; then "Success" fi But, if I try, if ; then "Success" fi Does not works ! Even, (4 Replies)
Discussion started by: angshuman_ag
4 Replies

4. Shell Programming and Scripting

Compare 3 files, delete data equals.

Hi, i have a problem, I have three files, file_1, File_2 file_3 and I need to compare the data with file_3 file_1, data that are equal to file_3 file_1 should be deleted, file_1 receive data and file_2 file_3. Ex: file_1 374905,2001, Selmar Santos, Técnico de Sistemas, U$3.000,00 789502,... (3 Replies)
Discussion started by: selmar
3 Replies

5. Shell Programming and Scripting

awk : Remove column1 and last column in a line

Hi All, How to remove col1 and last column in a line. Please suggest some awk stuffs. Input col1 col2 col3 col4 col1 col2 col3 col4 col5 col1 col2 col3 col4 col1 col2 col3 Output Processing col2 col3 ... Processing col2 col3 col4 ... Processing col2 col3 ... Processing... (5 Replies)
Discussion started by: k_manimuthu
5 Replies

6. Shell Programming and Scripting

How to output the partially equals

Hello i have 2 files: a.out 10.1.1.1 james.franco 10.1.1.3 google.gol 10.1.1.14 yahoo.bol b.out 10.1.1.1 10.1.1.3 10.1.1.45 I need to see an output just with: 10.1.1.1 james.franco 10.1.1.3 google.gol Thankz in advance!! (2 Replies)
Discussion started by: danielldf
2 Replies

7. Shell Programming and Scripting

[solved] how to check if two arrays are equals?

how to compare to arrays to check if each elements of the first are the same of the second? for ((i=0;i<$LENGTH;i++)) ; do for (j=0;j<$LENGTH;j++)) ; do if } == ${ARR2} ] echo "Are the same"; fi; done; done; i try this but it doesn't work :( if i make... (0 Replies)
Discussion started by: tafazzi87
0 Replies

8. UNIX for Dummies Questions & Answers

awk if statement / equals operator

Hi, I was hoping someone could explain this please :) I'm using bash, scientific linux... and I don't know what else you need to know. With awk '{ if( 0.3 == 0.1*3) print $1}' file.dat nothing will be printed since apparently the two numbers do not equate. (Using 0.3 != 0.1*3 is seen... (4 Replies)
Discussion started by: Golpette
4 Replies

9. UNIX for Dummies Questions & Answers

If variable equals string help

Hi All, Trying to get my bash script if statement to work however my if variable equals xxx statement doesnt appear to work, could anyone shed some light. ./script $password &> output INCORRECTPASS=`grep "Permission denied, please try again." output` echo "$INCORRECTPASS" ... (8 Replies)
Discussion started by: mutley2202
8 Replies

10. Shell Programming and Scripting

Do nothing if column1 is found

Hello, I have stucked at one point. When I run the script, I am asking the script to search in database file and if it's found, do nothing and proceed to next line in database file. #!/bin/bash ./extract_email.pl output2 > database while read -r COL1 X=$(grep $COL1 database ) if ]... (7 Replies)
Discussion started by: baris35
7 Replies
PREV(1) 							     [nmh-1.5]								   PREV(1)

NAME
prev - show the previous message SYNOPSIS
prev [+folder] [-showproc program] [-showmimeproc program] [-header | -noheader] [-checkmime | -nocheckmime] [switches for showproc or showmimeproc] [-version] [-help] DESCRIPTION
Prev performs a show on the previous message in the specified (or current) folder. Like show, it passes any switches on to the program named by showproc or showmimeproc, which is called to list the message. This command is almost exactly equivalent to "show prev". Consult the manual entry for show(1) for all the details. FILES
$HOME/.mh_profile The user profile PROFILE COMPONENTS
Path: To determine the user's nmh directory Current-Folder: To find the default current folder showproc: Program to show non-MIME messages showmimeproc: Program to show MIME messages SEE ALSO
show(1), next(1) DEFAULTS
`+folder' defaults to the current folder `-checkmime' `-header' CONTEXT
If a folder is specified, it will become the current folder. The message that is shown (i.e., the previous message in sequence) will become the current message. BUGS
prev is really a link to the show program. As a result, if you make a link to prev and that link is not called prev, your link will act like show instead. To circumvent this, add a profile-entry for the link to your nmh profile and add the argument prev to the entry. MH.6.8 11 June 2012 PREV(1)
All times are GMT -4. The time now is 05:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy