« first day (4329 days earlier)      last day (628 days later) » 

12:48 PM
@user1614432 here
You might not be able to write yet. One sec
OK, now you should be able to chat, @user1614432. You might need to reload the page though.
 
@terdon Hey, Now I'm able to talk.
 
Ah, excellent!
 
I'm Erikli. we were talking in comments
 
Yes, I know :)
 
How can I do this? I'm gonna be mad lol
 
12:54 PM
So, can you explain what you really need here? I mean, if what you want is to match 329, and NOT match 329 then why don't you just grep for 329,?
I mean, why does it matter if you would also get "Exists" for '329' if you don't use it?
What is the script really trying to do? What kind of searches?
 
It's a long story actually, I don't think that if my english will be enough for this but lets try
 
What's your native language? Your English seems fine!
 
Turkish
 
Ah, no, then I can't help all I know is a couple of swearwords :)
Let's try English. I'm sure you'll be fine.
 
:D Okey I'm trying
 
12:58 PM
Are you trying to process a .csv file?
 
lol
for the rest of us watching at home... link?
 
I'm currently writing a bash script. This bash script is installs some kind of applications. I have a manager menu for this applications. One of this application is a Music Bot. This Music Bot has some kind of permission system. If you want to add an admin you must edit a file. So I did a system for remembering old admins. It just prints admins to the file called admins. The numbers you saw is admin numbers. If you want to add multiple admins, then you have to seperate numbers with ",".
 
1
Q: How can I check if string exists in file

ErikliI'm currently writing a bash script. This bash script should check if the exact string 329, exists in myfile. I have searched through the web and found some answers, but I can't use -x parameters because I have more numbers than 329, on myfile. And without the -x parameter, I can get the Exists r...

@user1614432 ok
 
I was able to manage adding admins but now is the problem removing. For removing you must specify the "," so I can just remove it by sed. Otherwise it just brokes
Thats why I need it
I was gonna do if the grep output is "Exists" then remove it with "," else remove it normally
 
So you have a number in a variable, and you want to check if that exact number exists as a field in your file.
 
1:00 PM
Yes
 
Then why would you ever want to grep for 329? Is it because it could be the last number of the line so it would not have a , after it?
Like this:
2, 57, 329
 
Its just an example, every users admin is different in the app. Mine is 329 and I added it last. Thats why it doesn't have "," character. But for some people it might have "," character.
 
yes, exactly so what you want is i) match if you find 329 followed by , OR ii) match if 329 is the last thing on the line. Correct?
Does this do what you want:
 grep -Ew '329(,|$)' myfile
 
Let me check
 
(I had a typo which I corrected, make sure you copy this version)
 grep -Ew '329(,|$)' myfile
 
1:04 PM
Yes, It works
Thank you so much dude!
I was gonna be crazy while searching it lol
 
Yay! I updated my answer to cover that.
You're welcome :)
 
I accepted it as answer. Like I said thank you so much!
 
no problem, glad I could help
By the way @user1614432, you might find this post useful:
1237
A: How can I replace a string in a file(s)?

terdon1. Replacing all occurrences of one string with another in all files in the current directory: These are for cases where you know that the directory contains only regular files and that you want to process all non-hidden files. If that is not the case, use the approaches in 2. All sed solutions ...

 
 
1 hour later…
2:14 PM
@user1614432 I feel like a little bit of the config file for reference might make it easier
I tend to follow "this is what I have (config file), this is what I get (current way I am trying and the outout) and 'this is what I need' for questions like this
 
3:07 PM
@terdon Hello, Do you have some ideas how can I delete a specific string from a text file?
I was using this but it seems unstable..
sed -r "s#${Cevap34}(,|$)##g" <.adminsold >.admins
 
Please post a new question and make sure to include i) an example input file with lines that should be changed and some lines that should not be changed and ii) the output you expect. I need to run now so I can't help here.
I suspect you don't want the g though
 
When I post, can I send a link here for you?
@terdon I've posted. You can check;
https://askubuntu.com/questions/1422279/how-can-i-delete-specific-string-from-a-file
 
 
1 hour later…
4:48 PM
Hello @terdon, How can I check if a text file has ",,"? I tried your way but it didn't work. It just detects one ","
I found the answer but now I have another problem :D. I must delete one "," from ",,". Can't find it
Found an alternative for that. Forget about it
 

« first day (4329 days earlier)      last day (628 days later) »