Results 1 to 3 of 3
Thread: help with creating a bash script
-
04-28-2015, 08:51 AM #1Junior Guru
- Join Date
- Mar 2009
- Location
- /usr/bin
- Posts
- 217
help with creating a bash script
Hello friends
I'm trying to write a bash script to match 2 files and generate output
#1 file has
some_text 1
some_textx 2
some_texta 3
some_texte 4
1 aa
2 bb
3 cc
4 dd
some_text aa
some_textx bb
some_texta cc
some_texte dd
Cheerz
-
04-28-2015, 10:44 PM #2Total Nerd
- Join Date
- Feb 2007
- Location
- Florida
- Posts
- 1,932
This should work for you assuming the format for file one will always be <TEXT> <NUMBER> and file two will always be <NUMBER> <TEXT>:
Code:#!/bin/sh FILE1=/path/to/file1 FILE2=/path/to/file2 NUM=`cat $FILE1 | wc -l` COUNT=1 while [ $COUNT -le $NUM ]; do ONE=`cat $FILE1 | grep " $COUNT$" | /usr/bin/awk '{print $1}'` TWO=`cat $FILE2 | grep "^$COUNT " | /usr/bin/awk '{print $2}'` echo $ONE $TWO COUNT=$((COUNT + 1)) done
Code:# sh test.sh some_text aa some_textx bb some_texta cc some_texte dd some_texteb ee some_textec ff some_texted gg some_textee hh some_textef ii some_texteg jj some_texteh kk some_textei ll some_textej mm some_textek nn some_textel oo some_textem pp some_texten qq some_texteo rr some_textep ss some_texteq tt some_texter uu some_textes vv
-Joe @ Secure Dragon LLC.
+ OpenVZ Powered by Wyvern | KVM | cPanel Hosting | Backup VPSs | LowEndBoxes | DDOS Protection
+ Florida | Colorado | Illinois | California | Oregon | Georgia | New Jersey | Arizona | Texas
-
05-02-2015, 03:31 PM #3Disabled
- Join Date
- Apr 2015
- Posts
- 9
Well, You should learn C programming basic first then you can switch back to any others languages.
Similar Threads
-
[ Help ] Creating a bash script to install softwares?
By LFern in forum Programming DiscussionReplies: 1Last Post: 07-23-2011, 04:51 PM -
Help with creating a PHP script
By acctman in forum Programming DiscussionReplies: 4Last Post: 06-26-2006, 11:06 PM -
Help with small sh/cron script
By ReliableServers in forum Hosting Security and TechnologyReplies: 3Last Post: 10-26-2001, 06:59 PM -
Help with small sh/cron script
By ReliableServers in forum Dedicated ServerReplies: 1Last Post: 10-25-2001, 05:02 AM -
I need some help with creating...
By MySiteHost in forum Hosting Software and Control PanelsReplies: 5Last Post: 12-19-2000, 09:17 PM