Sponsored Content
Top Forums UNIX for Dummies Questions & Answers [Solved] Help to remove a line from a file Post 302732001 by samnyc on Friday 16th of November 2012 10:46:18 AM
Old 11-16-2012
Quote:
Originally Posted by in2nix4life
Code:
find /home -name 'known_hosts' -exec sed -i -e 's/txus03//g' {} \;

wow, you make it so simple, I was trying to do all kinds of crazy things. Thank you so much.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove header(first line) and trailer(last line) in ANY given file

Hi, I need some help in removing the header (first line) and the trailer (last line) in a give file... The data file actually comes in EBCDIC format and I converted it into ASCII.. Now I need to strip off the first line and the last line.. I think we can use sed to do something like this:... (2 Replies)
Discussion started by: madhunk
2 Replies

2. Shell Programming and Scripting

[Solved] Problem in reading a file line by line till it reaches a white line

So, I want to read line-by-line a text file with unknown number of files.... So: a=1 b=1 while ; do b=`sed -n '$ap' test` a=`expr $a + 1` $here do something with b etc done the problem is that sed does not seem to recognise the $a, even when trying sed -n ' $a p' So, I cannot read... (3 Replies)
Discussion started by: hakermania
3 Replies

3. Shell Programming and Scripting

[Solved] Read a .gz file line by line without using gzcat

Hi all Is there a way to read and process a gzip file line by line similar to a text file without using gzcat.. while processing a text file we will usually use the logic exec<sample.txt while read line do echo $line done Is there a similar way to process the gz file in the same... (4 Replies)
Discussion started by: aikhaman
4 Replies

4. UNIX for Dummies Questions & Answers

[Solved] Rename file name / remove part of name

I have a whole file structure with jpeg files where I want to remove a part of the file name. An application added in many files a case conflict in the naming "xyz 017.jpg (Case Conflict 1)" So, can someone help me how to get rid of the " (Case Conflict 1)"? What I have is this: find . -name... (2 Replies)
Discussion started by: borobudur
2 Replies

5. Shell Programming and Scripting

[SOLVED] Sorting file and get everything on same line on condition

Good afternoon! I am a perl newbie. I hope you will be patient with me. I have a script that needs to be written in perl. I can't do it in awk or shell scripting. Here is the script: #!/usr/bin/perl use POSIX qw(strftime); use FileHandle; use Getopt::Long; use IO::Handle;... (0 Replies)
Discussion started by: brianjb
0 Replies

6. Shell Programming and Scripting

[Solved] remove file extension

Hi, I have some files with some extension e.g. abc.xml.REMOVE,xyz.xml,efg.xml.REMOVE . I have to remove the .REMOVE extension. I can display it using the below script but cannot rename it. ls -l|sed 's/\.REMOVE//' How can I rename this? Thanks in advance (7 Replies)
Discussion started by: babom
7 Replies

7. Shell Programming and Scripting

[Solved] Remove file older than 90 days

I have crontab job a tar file to a directory ( tar -cvf /tmp/backup/or.`date +%m%d%y`. /ora/db/* ) , it will do it every day . Now I don't want to keep too much files , I just want to keep the file for 90 days , can advise if I want to remove the backup file which are elder than 90 days , can... (1 Reply)
Discussion started by: ust3
1 Replies

8. UNIX for Dummies Questions & Answers

[Solved] New Line in file

Hi, Though I was successful in following query, I like to know the other ways of doing it. I have a file that is sent as an attachment via mail. However, while opening it, notepad does not recognize new line character whereas other editors like text pad recognizes new line character of unix.... (2 Replies)
Discussion started by: bobbygsk
2 Replies

9. Shell Programming and Scripting

[Solved] Howto remove extra space in the file

Hi Gurus, I have a file which contains some special char or space. when using cat -evt I can see the file as following: 0,"0000","abc/def aaa ... (6 Replies)
Discussion started by: ken6503
6 Replies
MongoDB::Examples(3pm)					User Contributed Perl Documentation				    MongoDB::Examples(3pm)

NAME
MongoDB::Examples - Some examples of MongoDB syntax MAPPING SQL TO MONGODB
For developers familiar with SQL, the following chart should help you see how many common SQL queries could be expressed in MongoDB. These are Perl-specific examples of translating SQL queries to MongoDB's query language. To see the JavaScript (or other languages') mappings, see <http://dochub.mongodb.org/core/sqlToMongo>. "CREATE TABLE USERS (a Number, b Number)" Implicit, can be done explicitly. "INSERT INTO USERS VALUES(1,1)" $db->users->insert({a => 1, b => 1}); "SELECT a,b FROM users" $db->users->find({}, {a => 1, b => 1}); "SELECT * FROM users" $db->users->find; "SELECT * FROM users WHERE age=33" $db->users->find({age => 33}) "SELECT a,b FROM users WHERE age=33" $db->users->find({age => 33}, {a => 1, b => 1}); "SELECT * FROM users WHERE age=33 ORDER BY name" $db->users->find({age => 33})->sort({name => 1}); "<SELECT * FROM users WHERE age"33>> $db->users->find({age => {'$gt' => 33}}) "<SELECT * FROM users WHERE age<33"> $db->users->find({age => {'$lt' => 33}}) "SELECT * FROM users WHERE name LIKE "%Joe%"" $db->users->find({name => qr/Joe/}); "SELECT * FROM users WHERE name LIKE "Joe%"" $db->users->find({name => qr/^Joe/}); "<SELECT * FROM users WHERE age"33 AND age<=40>> $db->users->find({age => {'$gt' => 33, '$lte' => 40}}); "SELECT * FROM users ORDER BY name DESC" $db->users->find->sort({name => -1}); "CREATE INDEX myindexname ON users(name)" $db->users->ensure_index({name => 1}); "CREATE INDEX myindexname ON users(name,ts DESC)" $db->users->ensure_index(Tie::IxHash->new(name => 1, ts => -1)); "SELECT * FROM users WHERE a=1 and b='q'" $db->users->find({a => 1, b => "q"}); "SELECT * FROM users LIMIT 10 SKIP 20" $db->users->find->limit(10)->skip(20); "SELECT * FROM users WHERE a=1 or b=2" $db->users->find({'$or' => [{a => 1}, {b => 2}]}); "SELECT * FROM users LIMIT 1" $db->users->find->limit(1); "EXPLAIN SELECT * FROM users WHERE z=3" $db->users->find({z => 3})->explain; "SELECT DISTINCT last_name FROM users" $db->run_command({distinct => "users", key => "last_name"}); "SELECT COUNT(*y) FROM users" $db->users->count; "<SELECT COUNT(*y) FROM users where age " 30>> $db->users->find({"age" => {'$gt' => 30}})->count; "SELECT COUNT(age) from users" $db->users->find({age => {'$exists' => 1}})->count; "UPDATE users SET a=1 WHERE b='q'" $db->users->update({b => "q"}, {'$set' => {a => 1}}); "UPDATE users SET a=a+2 WHERE b='q'" $db->users->update({b => "q"}, {'$inc' => {a => 2}}); "DELETE FROM users WHERE z="abc"" $db->users->remove({z => "abc"}); DATABASE COMMANDS
Distinct The distinct command returns all values for a given key in a collection. For example, suppose we had a collection with the following documents ("_id" value ignored): { 'name' => 'a', code => 1 } { 'name' => 'b', code => 1 } { 'name' => 'c', code => 2 } { 'name' => 'd', code => "3" } If we wanted to see all of values in the "code" field, we could run: my $result = $db->run_command([ "distinct" => "collection_name", "key" => "code", "query" => {} ]); Notice that the arguments are in an array, to ensure that their order is preserved. You could also use a Tie::IxHash. "query" is an optional argument, which can be used to only run "distinct" on specific documents. It takes a hash (or Tie::IxHash or array) in the same form as "find($query)" in MongoDB::Collection. Running "distinct" on the above collection would give you: { 'ok' => '1', 'values' => [ 1, 2, "3" ] }; Find-and-modify The find-and-modify command is similar to update (or remove), but it will return the modified document. It can be useful for implementing queues or locks. For example, suppose we had a list of things to do, and we wanted to remove the highest-priority item for processing. We could do a "find" in MongoDB::Collection and then a "remove" in MongoDB::Collection, but that wouldn't be atomic (a write could occur between the query and the remove). Instead, we can use find and modify. my $next_task = $db->run_command({ findAndModify => "todo", sort => {priority => -1}, remove => 1 }); This will atomically find and pop the next-highest-priority task. See <http://www.mongodb.org/display/DOCS/findAndModify+Command> for more details on find-and-modify. Group The group command is similar to "GROUP BY" in SQL. You can use the "run_command" in MongoDB::Database method to perform group-bys with MongoDB. For example, suppose we have a number of local businesses stored in a "business" collection. If we wanted to find the number of coffeeshops in each neighborhood, we could do: my $reduce = <<REDUCE; function(doc, prev) { for (var t in doc.tags) { if (doc.tags[t] == "coffeeshop") { prev["num coffeeshops"]++; break; } } } REDUCE my $result = $db->run_command({group => { 'ns' => "business", 'key' => {"neighborhood" => 1}, 'initial' => {"num coffeeshops" => 0}, '$reduce' => MongoDB::Code->new(code => $reduce) This would return something like: { 'ok' => '1', 'keys' => 4, 'count' => '487', # total number of documents 'retval' => [ { 'neighborhood' => 'Soho', 'num coffeeshops' => '23' }, { 'neighborhood' => 'Chinatown', 'num coffeeshops' => '14' }, { 'neighborhood' => 'Upper East Side', 'num coffeeshops' => '10' }, { 'neighborhood' => 'East Village', 'num coffeeshops' => '87' } ] }; Thus, there are 23 coffeeshops in Soho, 14 in Chinatown, and so on. See <http://www.mongodb.org/display/DOCS/Aggregation> for more details on grouping. MapReduce MapReduce is a powerful aggregation tool. (For traditional queries, you should use "MongoDB::Collection::query".) This example counts the number of occurences of each tag in a collection. Each document contains a "tags" array that contains zero or more strings. my $map = <<MAP; function() { this.tags.forEach(function(tag) { emit(tag, {count : 1}); }); } MAP my $reduce = <<REDUCE; function(prev, current) { result = {count : 0}; current.forEach(function(item) { result.count += item.count; }); return result; } REDUCE my $cmd = Tie::IxHash->new("mapreduce" => "foo", "map" => $map, "reduce" => $reduce); my $result = $db->run_command($cmd); See the MongoDB documentation on MapReduce for more information (<http://dochub.mongodb.org/core/mapreduce>). UPDATING
Positional Operator In MongoDB 1.3.4 and later, you can use positional operator, "$", to update elements of an array. For instance, suppose you have an array of user information and you want to update a user's name. A sample document in JavaScript: { "users" : [ { "name" : "bill", "age" : 60 }, { "name" : "fred", "age" : 29 }, ] } The update: $coll->update({"users.name" => "fred"}, {'users.$.name' => "george"}); This will update the array so that the element containing "name" => "fred" now has "name" => "george". perl v5.14.2 2011-08-29 MongoDB::Examples(3pm)
All times are GMT -4. The time now is 09:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy