LINUX to UNIX... changes needed?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers LINUX to UNIX... changes needed?
# 8  
Old 12-06-2010
This "monica.txt" file isn't text, it's RTF! Hoping you knew that, but maybe you didn't. Substitution's still possible of course.

Boy, it's sure obnoxious having to work with BSD sed after having used GNU sed... Things any rational person would guess were basic, basic, basic features, like \n, don't work.

I did eventually manage to get it to do this:

Code:
$ echo "abc;;;def" | sed 's/;;;/\
/g'
abc
def
$

Yes, that is a literal newline inside the expression. You have to put a \ before the enter key to "escape" it or BSD sed will whine about it. It may be possible to substitute it in by putting the expression in double quotes, and using $'\n', but this may be more trouble than it's worth and involve outrageous numbers of backslashes.

By the way, 'cat file | program' is a useless use of cat. You can do it faster and just as simply with
Code:
program < file

or, if you prefer the file being in front, that works too:
Code:
< file program

# 9  
Old 12-06-2010
Please attach files in a flat format. Anyway, assuming the first instance of ";;;;" is on the first line:
Code:
awk 'NR==1{next}
!c || /;;;/{sub(";;;",""); c=sprintf("%04d",++i); close("comment" c ".txt")}
{print > "comment" c ".txt"}' monica.txt

Use nawk or /usr/xpg4/bin/awk on Solaris.
# 10  
Old 12-07-2010
Quote:
Originally Posted by royalibrahim
To me, I am getting no error but no splitting happens.

Here's my code.

Code:
echo "f1;f2;f3" | awk '/;/{c=sprintf("%02d",++i); close("out" c)} {print > "out" c}'

Code:
echo "f1;f2;f3" | awk -v i=0 '/;/{close("out"i); i++; next} {print > "out"i}'

Please let me know where I have gone wrong?
Could any one tell me why this splitting code does not work?
# 11  
Old 12-07-2010
Quote:
Originally Posted by Franklin52
Please attach files in a flat format. Anyway, assuming the first instance of ";;;;" is on the first line:
Code:
awk 'NR==1{next}
!c || /;;;/{sub(";;;",""); c=sprintf("%04d",++i); close("comment" c ".txt")}
{print > "comment" c ".txt"}' monica.txt

Use nawk or /usr/xpg4/bin/awk on Solaris.
I hate to be a pain, but I'm still getting the return "awk: illegal statement at source line 3
context is
{print > "comment" >>> c <<< ".txt"}" when I run this code. Does anyone know how what is wrong with the third line?

---------- Post updated at 01:25 AM ---------- Previous update was at 01:22 AM ----------

Quote:
Originally Posted by Corona688
This "monica.txt" file isn't text, it's RTF! Hoping you knew that, but maybe you didn't. Substitution's still possible of course.

Boy, it's sure obnoxious having to work with BSD sed after having used GNU sed... Things any rational person would guess were basic, basic, basic features, like \n, don't work.

I did eventually manage to get it to do this:

Code:
$ echo "abc;;;def" | sed 's/;;;/\
/g'
abc
def
$

Yes, that is a literal newline inside the expression. You have to put a \ before the enter key to "escape" it or BSD sed will whine about it. It may be possible to substitute it in by putting the expression in double quotes, and using $'\n', but this may be more trouble than it's worth and involve outrageous numbers of backslashes.
]
Excuse my ignorance, but what do you mean by "newline inside the expression"? What would the full complete code be, exactly?
# 12  
Old 12-09-2010
Quote:
Originally Posted by mschpers
Excuse my ignorance, but what do you mean by "newline inside the expression"?
Exactly what I said, no more, no less. The newline isn't represented by \n or anything. There's a real, actual newline inside the string. Note how one string crosses two lines:
Code:
$ echo "abc;;;def" | sed 's/;;;/\
/g'
abc
def
$

Quote:
What would the full complete code be, exactly?
Code:
sed 's/;;;/\
/g' < input > output

# 13  
Old 12-09-2010
tr with -s option will also do the job
Code:
$ echo "abc;;;def" | tr -s  ';;;' '\n'
abc
def
$

# 14  
Old 12-09-2010
Quote:
Originally Posted by mschpers
Basically, I want it to take the file monica.txt and put every instance of ;;; on a new line and put it in fixed.txt, then split fixed.txt at every instance of ;;; and put it in new files called comment0001.txt, comment0002.txt,... comment2500.txt.
This is my output with a snippet of your file:

Code:
~/awktest$ ls -l
total 4
-rw-r--r-- 1 user user 507 2010-12-09 18:58 monica.txt

Code:
~/awktest$ cat monica.txt 
Huh. Okay. I'll be interested to see how this goes. posted by MF099 <*2:06 PM *#699152>*on October 31 ;;;

*faved* posted by MF018 <*2:09 PM *#699154>*on October 31 ;;;


Hmmm. Will this be site wide? I feel like in AskMe the visible favorite count often functions as "I would like to agree 
with this answer" as opposed to "I would like to reward this snark". posted by MF542 <*2:16 PM *#699155>*on October 31 ;;;


It'll be site wide, yes. posted by MF531 <*2:17 PM *#699156>*on October 31 ;;;

Code:
~/awktest$ awk '
!c || /;;;/{c=sprintf("%04d",++i); close("comment" c ".txt")}
{print > "comment" c ".txt"}' monica.txt

Code:
~/awktest$ ls -l
total 20
-rw-r--r-- 1 user user 110 2010-12-09 18:59 comment0001.txt
-rw-r--r-- 1 user user  67 2010-12-09 18:59 comment0002.txt
-rw-r--r-- 1 user user 248 2010-12-09 18:59 comment0003.txt
-rw-r--r-- 1 user user  82 2010-12-09 18:59 comment0004.txt
-rw-r--r-- 1 user user 507 2010-12-09 18:58 monica.txt

Code:
~/awktest$ cat comment0001.txt 
Huh. Okay. I'll be interested to see how this goes. posted by MF099 <*2:06 PM *#699152>*on October 31 ;;;

~/awktest$ cat comment0002.txt 
*faved* posted by MF018 <*2:09 PM *#699154>*on October 31 ;;;

Am I missing something?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Linux router help needed

hi guys. I have an Kaon router wich runs "Linux version 3.10.24-svn1480 (jskim@jake-205) (gcc version 4.4.7 (Realtek MSDK-4.4.7 Build 1459". The problem I have it is that its firmware is in early stages and has alot of things messed up. Wake on lan doesn't work without arp binding and that can... (23 Replies)
Discussion started by: apoklyps3
23 Replies

2. Shell Programming and Scripting

Linux command needed

guys im new here and i need help with some linux commands. filea has keyword on each line identity aaa bbb ccc i have following commands. egrep 'www.identity' ~/home/m3 >~/home/lopo2 wc -l file ~/home/lopo2 say lopo2 has 44 lines then output saved is identity 44 (1 Reply)
Discussion started by: ahfze
1 Replies

3. Red Hat

Installing Linux on Vmware - Help needed

Hi Friends I am trying to install linux (32 bit) on windows. so i used Oracle virtual box and Vmware player in windows and installed them. but there is no category to select Linux version 7. how to install it pls help here. (7 Replies)
Discussion started by: ded325
7 Replies

4. Homework & Coursework Questions

Linux/UNIX Bash Shell Script trouble help needed!!

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 2. Shell Bash Script 3. !/bin/bash if echo no directory then mkdir -p /home/AC_Drywall elif ; then echo "$dir already exist" fi (4 Replies)
Discussion started by: TomFord1
4 Replies

5. Shell Programming and Scripting

Command needed in linux flavour OS

HI, My requirement as below Log with Error Code: Starting FeedRunner for feed: 200 Product example Items Error FeedRunner for feed: 200 Product example Items Stopping FeedRunner for feed : 200 Product example Items Feed time taken 231743 Log without Error Code: ... (0 Replies)
Discussion started by: Paulwintech
0 Replies

6. UNIX for Dummies Questions & Answers

Linux Tutorial Needed

Hi guys , I m new to linux and would like to buy some quality video tutorials . Request you to guide me any good source for programming(C,Java,VB) or linux tutorials. Tutorials should be known and good like lynda.com (5 Replies)
Discussion started by: pinga123
5 Replies

7. Programming

Help needed linux socket programming in c

Good evening everyone! :) I'm doing a small client / server application for sharing files in C, and I am trying to implement the following: The client of my application sends to the address 255.255.255.255 a message requesting a particular file.In the network there is only one server,... (1 Reply)
Discussion started by: esmeco
1 Replies

8. Shell Programming and Scripting

Linux starter help needed

:confused: hi guys i'm helping out as a lab assistant and have been told to use a linux shell script to gather assignments from the students in the class I'm helping out in. They've been told to have their assignment in a certain folder in their accounts and I'm to gather them, only problem is I... (0 Replies)
Discussion started by: jaybee
0 Replies
Login or Register to Ask a Question