How can i split this.. :)?


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can i split this.. :)?
# 1  
Scissors How can i split this.. :)?

hello, Smilie
How can i split this.. Smilie

10.25.10.2

two octet

a=2
b=5

Thank you...
# 2  
What have you tried?
This should be a pretty simple thing to do with cut or awk commands.
# 3  
i maked this.

Code:
#!/usr/bin/env bash

read ip

oktet1=`echo $ip | cut -d \. -f 1`
oktet2=`echo $ip | cut -d \. -f 2`
oktet3=`echo $ip | cut -d \. -f 3`
oktet4=`echo $ip | cut -d \. -f 3`

echo $oktet1
echo $oktet2
echo $oktet3
echo $oktet4

but i want cut secon octet on ip (eg:192.168.1.1)
168
a=1
b=6
c=8
thank you for your reply.
# 4  
You did not show the output of your commands.
Does you second command give you the second number you wish to split?

Code:
oktet2=`echo $ip | cut -d \. -f 2`

If so, then perhaps split that variable oktet2...
# 5  
example:
Code:
read ip
192.168.1.1

oktet1=`echo $ip | cut -d \. -f 1`
oktet2=`echo $ip | cut -d \. -f 2`
oktet3=`echo $ip | cut -d \. -f 3`
oktet4=`echo $ip | cut -d \. -f 3`

echo $oktet1
echo $oktet2
echo $oktet3
echo $oktet4

192
168
1
1


I want to shred "168" Is it possible?

Moderator's Comments:
Mod Comment
Please wrap all code, files, input & output/errors in CODE tags.
It makes them far easier to read and preserves spacing for indenting and fixed-width data.

Last edited by bakunin; 01-18-2017 at 04:59 PM.. Reason: Added code tags, corrected center-tags
# 6  
Code:
IFS="." read A B C D

No externals needed.

Rearrange A B C D however you please to get the order you want.
# 7  
Thanks Corona688..

i make this

Code:
IFS="." read A B C D
echo $A
echo $B

in>192.168.1.1
output>
Code:
192
168


I already do that. I also want to separate the number 168

example>
Code:
1
6
8


Last edited by rbatte1; 01-18-2017 at 08:38 AM..
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #641
Difficulty: Medium
NeXTSTEP had a Unix operating system based on the Minix kernel, plus source code from System V.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Split and Rename Split Files

Hello, I need to split a file by number of records and rename each split file with actual filename pre-pended with 3 digit split number. What I have tried is the below command with 2 digit numeric value split -l 3 -d abc.txt F (# Will Produce split Files as F00 F01 F02) How to produce... (19 Replies)
Discussion started by: techedipro
19 Replies

2. AIX

LV split...

Hi all, I have a strange problem that I have finally given up on and thought id start hitting the forums.. Any help is greatly appreiciated. I have recently attached two new physical disks to my system and created a new volume group which inlcude these. My aim, is to create a logical volume of... (1 Reply)
Discussion started by: Dansey
1 Replies

3. Shell Programming and Scripting

awk to split one field and print the last two fields within the split part.

Hello; I have a file consists of 4 columns separated by tab. The problem is the third fields. Some of the them are very long but can be split by the vertical bar "|". Also some of them do not contain the string "UniProt", but I could ignore it at this moment, and sort the file afterwards. Here is... (5 Replies)
Discussion started by: yifangt
5 Replies

4. Shell Programming and Scripting

Split

Hello people, I have a huge file of say 1 gb called A123.txt.. to get the word count, i do wc -l A123.txt This gives me a count of say 122898. Now what i do is, i divide this by 4 ie. 122888/4=30722 Now i copy the content as per the above count (30722) and give some name to... (6 Replies)
Discussion started by: j_panky
6 Replies

5. Shell Programming and Scripting

split()

Hi there, Can someone tell me why the why the element of output is not the same order as the original data? Below is the value of column 11 of 2nd line,... (4 Replies)
Discussion started by: phoeberunner
4 Replies

6. Shell Programming and Scripting

split -d

pls explain me about split -d option with syntax and an example.. thanks (1 Reply)
Discussion started by: vijay_0209
1 Replies

7. Shell Programming and Scripting

help with split

I have a file that reads "#ID, First, P1(40), P2(40), P3(40)..." and I need to split this line up. I first did @scores = split(/,/, $input); But I need to split it up and get the the parentheses with numbers split up too, in order to add them together later. I know I need to do at least... (1 Reply)
Discussion started by: Hawks444
1 Replies

8. UNIX for Dummies Questions & Answers

Split a file with no pattern -- Split, Csplit, Awk

I have gone through all the threads in the forum and tested out different things. I am trying to split a 3GB file into multiple files. Some files are even larger than this. For example: split -l 3000000 filename.txt This is very slow and it splits the file with 3 million records in each... (10 Replies)
Discussion started by: madhunk
10 Replies

9. Shell Programming and Scripting

Split by comma

Hi all, for i in `cat /tmp/tester.txt` do echo $i done The content of /tmp/tester.txt is as below 1001,asp 1002,java 1003,vc Now when I try the above program it gives me a output in the same way as below. 1001,asp 1002,java 1003,vc (2 Replies)
Discussion started by: mahalakshmi
2 Replies

10. UNIX for Dummies Questions & Answers

Split

Is there a split function in shell? (not awk) Coz i got a string as input and needed to split it. eg. input = "abc:123:def:www" I need to split it into 4 variable which contains abc,123,def,www. Is there anyway i can do tat? (1 Reply)
Discussion started by: AkumaTay
1 Replies

Featured Tech Videos