LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-28-2014, 12:57 PM   #1
desiretolearn
LQ Newbie
 
Registered: Jan 2014
Posts: 25

Rep: Reputation: Disabled
:) assistance required


hi all
i want to split a file using commandline argument
i have tried
split -l 2 filename


please give your suggestions
thanks in advance

Last edited by desiretolearn; 02-04-2014 at 05:05 AM.
 
Old 01-28-2014, 01:04 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 4,483
Blog Entries: 10

Rep: Reputation: 1641Reputation: 1641Reputation: 1641Reputation: 1641Reputation: 1641Reputation: 1641Reputation: 1641Reputation: 1641Reputation: 1641Reputation: 1641Reputation: 1641
Well where are you supposed to get the value from?
 
Old 01-28-2014, 01:36 PM   #3
turnerbm125
LQ Newbie
 
Registered: Jan 2014
Posts: 1

Rep: Reputation: Disabled
assistance required :) - why not use grep?

Dear assistance required,
why not use grep (assuming you have a phrase to use as a tag):
I created a text file with 54 lines (evenOdd.txt):
- every other line had the tag "even" or "odd"
- used the following on the command line to separate "even" and "odd" lines:
cat evenOdd.txt | grep -i even > evenOnly.txt (27 lines resulted - all with "even")
cat evenOdd.txt | grep -i odd > oddOnly.txt (27 lines resulted - all with "odd")
I know this is a fairly simple example, but you get the idea.
The split command assumes you want a certain number of lines regardless of the content.
Does this help?
 
1 members found this post helpful.
Old 01-28-2014, 09:43 PM   #4
desiretolearn
LQ Newbie
 
Registered: Jan 2014
Posts: 25

Original Poster
Rep: Reputation: Disabled
thanks guys
but when i execute my script
say ./abc.sh 1000 47 48
it must split the file
 
Old 01-29-2014, 12:35 AM   #5
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 16,986

Rep: Reputation: 2447Reputation: 2447Reputation: 2447Reputation: 2447Reputation: 2447Reputation: 2447Reputation: 2447Reputation: 2447Reputation: 2447Reputation: 2447Reputation: 2447
split the file HOW ??????
50/50 ?
first 1000 lines then the rest ?
or first 64 Bits of the file ,then the rest ( this is a bit common in binary image files) ?
even / odd lines ?
How ?
 
1 members found this post helpful.
Old 01-29-2014, 12:59 AM   #6
desiretolearn
LQ Newbie
 
Registered: Jan 2014
Posts: 25

Original Poster
Rep: Reputation: Disabled
First file having 2 records and last file having 5 and rest will have 1000 records each.
 
Old 01-29-2014, 01:01 AM   #7
desiretolearn
LQ Newbie
 
Registered: Jan 2014
Posts: 25

Original Poster
Rep: Reputation: Disabled
i have split the first and the last file i want to split the remaining files using command line arguments
 
Old 01-29-2014, 01:43 AM   #8
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,511

Rep: Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434
what have you implemented so far?
 
Old 01-29-2014, 02:08 AM   #9
desiretolearn
LQ Newbie
 
Registered: Jan 2014
Posts: 25

Original Poster
Rep: Reputation: Disabled
while {
n=0
while IFS= read -r line && [ $(( n+=1 )) -le 100 ]
do
printf "%s\n" "$line"
done
split -l1000 - outfile
} < infile > outfilea0


but i want to split it using command line values
 
Old 01-29-2014, 08:28 AM   #10
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 4,483
Blog Entries: 10

Rep: Reputation: 1641Reputation: 1641Reputation: 1641Reputation: 1641Reputation: 1641Reputation: 1641Reputation: 1641Reputation: 1641Reputation: 1641Reputation: 1641Reputation: 1641
Bash command line substitutes from within the script are:

Code:
$# - gives you the number of arguments passed to you
$1 - gives you argument number 1, like if you typed "<my-script> 1000", $1 is 1000
Try echo'ing this information:

Code:
echo "The number of arguments passed is: $#"
echo "Argument #1 is: $1"
And you can of course use the number of arguments as a loop limit value and perform tests:

Code:
if [ $# < 1 ]; then
    echo "Usage: script-name <argument>"
    exit 1;
fi
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Assistance required Laksh Linux - Laptop and Netbook 2 12-28-2008 10:50 AM
Required Assistance in Mandriva tuannie Linux - Software 6 07-06-2006 12:16 PM
assistance required v.s.sankar Linux - Certification 4 05-02-2006 09:01 AM
NVidia assistance required Hubmasterflex Linux - Hardware 9 01-27-2006 11:36 PM
Gotomail Configuration assistance required jefx Linux - Software 4 05-04-2003 10:59 AM


All times are GMT -5. The time now is 01:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration